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:
Herbie Ong 2020-02-06 10:59:01 -08:00
parent 4eefd77886
commit 4e6b903e61
2 changed files with 12 additions and 0 deletions

View File

@ -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()

View File

@ -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{