internal/encoding/json: fix crash in parsing

Fuzzer-detected crash when parsing: {""

Change-Id: I019c667f48e6a1237858b5abf7d34f43593fb3b6
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/212357
Reviewed-by: Herbie Ong <herbie@google.com>
This commit is contained in:
Damien Neil 2019-12-21 09:45:00 -08:00
parent f2427c09d6
commit 5ba0c29655
2 changed files with 10 additions and 0 deletions

View File

@ -102,6 +102,9 @@ func (d *Decoder) Read() (Value, error) {
}
d.in = d.in[n:]
d.consume(0)
if len(d.in) == 0 {
return Value{}, d.newSyntaxError(`unexpected EOF, missing ":" after object name`)
}
if c := d.in[0]; c != ':' {
return Value{}, d.newSyntaxError(`unexpected character %v, missing ":" after object name`, string(c))
}

View File

@ -872,6 +872,13 @@ func TestDecoder(t *testing.T) {
{E: `unexpected EOF`},
},
},
{
input: `{""`,
want: []R{
{T: json.StartObject},
{E: `syntax error (line 1:4): unexpected EOF`},
},
},
{
input: `{"34":"89",}`,
want: []R{