mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-03-15 22:20:52 +00:00
internal/encoding/text: fix eof crash when parsing list of scalars
Need to check for EOF and return proper error. Bug caught by fuzz test: https://oss-fuzz.com/testcase-detail/6258064955277312. Change-Id: I63d5c12c301f2ddefc9a0813c13abef40d745e91 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/218258 Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
This commit is contained in:
parent
4eefd77886
commit
4e6b903e61
@ -166,6 +166,9 @@ func (d *Decoder) parseNext(lastKind Kind) (Token, error) {
|
||||
|
||||
case ListOpen:
|
||||
// Next token can be ListClose or comma.
|
||||
if isEOF {
|
||||
return Token{}, io.ErrUnexpectedEOF
|
||||
}
|
||||
switch ch := d.in[0]; ch {
|
||||
case ']':
|
||||
d.popOpenStack()
|
||||
|
@ -732,6 +732,15 @@ func TestDecoder(t *testing.T) {
|
||||
{E: `(line 1:8): invalid scalar value: ,`},
|
||||
},
|
||||
},
|
||||
{
|
||||
in: `name: [0`,
|
||||
want: []R{
|
||||
{K: text.Name},
|
||||
{K: text.ListOpen},
|
||||
{K: text.Scalar},
|
||||
{E: eofErr},
|
||||
},
|
||||
},
|
||||
{
|
||||
in: `name: [` + space + `"hello"` + space + `]` + space,
|
||||
want: []R{
|
||||
|
Loading…
x
Reference in New Issue
Block a user