mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-17 01:12:51 +00:00
encoding/prototext: fix crash in map parsing
Fuzzer-detected crash when parsing map values which should be messages, but are not. Fixes golang/protobuf#1003 Change-Id: Ib34b13d1a6fef7209e7c17dc5d7f4bd8a1ebac87 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/212397 Reviewed-by: Herbie Ong <herbie@google.com>
This commit is contained in:
parent
5ba0c29655
commit
1a08d54978
@ -420,10 +420,14 @@ func unmarshalMapKey(input text.Value, fd pref.FieldDescriptor) (pref.MapKey, er
|
||||
|
||||
// unmarshalMapMessageValue unmarshals given message-type text.Value into a protoreflect.Map for
|
||||
// the given MapKey.
|
||||
func (o UnmarshalOptions) unmarshalMapMessageValue(input text.Value, pkey pref.MapKey, _ pref.FieldDescriptor, mmap pref.Map) error {
|
||||
func (o UnmarshalOptions) unmarshalMapMessageValue(input text.Value, pkey pref.MapKey, fd pref.FieldDescriptor, mmap pref.Map) error {
|
||||
var value [][2]text.Value
|
||||
if input.Type() != 0 {
|
||||
switch input.Type() {
|
||||
case 0:
|
||||
case text.Message:
|
||||
value = input.Message()
|
||||
default:
|
||||
return errors.New("%v contains invalid value: %v", fd.FullName(), input)
|
||||
}
|
||||
val := mmap.NewValue()
|
||||
if err := o.unmarshalMessage(value, val.Message()); err != nil {
|
||||
|
@ -948,6 +948,16 @@ int32_to_str: {
|
||||
key: 100
|
||||
value: 101
|
||||
}
|
||||
`,
|
||||
wantErr: true,
|
||||
}, {
|
||||
desc: "map contains invalid message value",
|
||||
inputMessage: &pb3.Maps{},
|
||||
inputText: `
|
||||
str_to_nested: {
|
||||
key: "one"
|
||||
value: 1
|
||||
}
|
||||
`,
|
||||
wantErr: true,
|
||||
}, {
|
||||
|
Loading…
Reference in New Issue
Block a user