mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 11:58:21 +00:00
internal/encoding/text: fix parsing of incomplete numbers
Fix a panic when parsing the incomplete negative number "- ". Fixes golang/protobuf#1530 Change-Id: Iba5e8ee68d5f7255c28f1a74f31beee36c9ed847 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/475995 Reviewed-by: Lasse Folger <lassefolger@google.com> Run-TryBot: Damien Neil <dneil@google.com>
This commit is contained in:
parent
fe5bc54041
commit
edaf511a7a
@ -308,6 +308,11 @@ s_string: "谷歌"
|
||||
inputMessage: &pb3.Scalars{},
|
||||
inputText: "s_sfixed64: bad",
|
||||
wantErr: "invalid value for sfixed64",
|
||||
}, {
|
||||
desc: "incomplete number value",
|
||||
inputMessage: &pb3.Scalars{},
|
||||
inputText: `s_int32: - `,
|
||||
wantErr: "(line 1:10): invalid scalar value: -",
|
||||
}, {
|
||||
desc: "conformance: FloatFieldMaxValue",
|
||||
inputMessage: &pb2.Scalars{},
|
||||
|
@ -88,15 +88,15 @@ func parseNumber(input []byte) number {
|
||||
neg = true
|
||||
s = s[1:]
|
||||
size++
|
||||
if len(s) == 0 {
|
||||
return number{}
|
||||
}
|
||||
// Consume any whitespace or comments between the
|
||||
// negative sign and the rest of the number
|
||||
lenBefore := len(s)
|
||||
s = consume(s, 0)
|
||||
sep = lenBefore - len(s)
|
||||
size += sep
|
||||
if len(s) == 0 {
|
||||
return number{}
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
|
@ -559,6 +559,14 @@ func TestDecoder(t *testing.T) {
|
||||
in: "- \t 123.321e6",
|
||||
want: []R{{E: "invalid field number: -123.321e6"}},
|
||||
},
|
||||
{
|
||||
in: "-",
|
||||
want: []R{{E: "invalid field name: -"}},
|
||||
},
|
||||
{
|
||||
in: "- ",
|
||||
want: []R{{E: "invalid field name: -"}},
|
||||
},
|
||||
{
|
||||
in: "- # negative\n 123",
|
||||
want: []R{{E: "invalid field number: -123"}},
|
||||
|
Loading…
Reference in New Issue
Block a user