unknownproto: check result from protowire.ConsumeFieldValue and return an error (#7770)
* unknownproto: check result from protowire.ConsumeFieldValue and return error Given that protowire.ConsumeFieldValue returns -1 when it encounters an error, perform a check for n < 0 and return the respectively obtained error with context about the details. Fixes an issue identified from a go-fuzz session, thanks to Ethan Buchman and the IBC auditors from Informal Systems et al. Fixes #7739. * Address AlexanderBez's suggestions * Use require in tests * Add issue #7846 to TODO Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
mergify[bot]
parent
55772aec8c
commit
fe8a891f11
@@ -92,6 +92,11 @@ func RejectUnknownFields(bz []byte, msg proto.Message, allowUnknownNonCriticals
|
||||
// Skip over the bytes that store fieldNumber and wireType bytes.
|
||||
bz = bz[m:]
|
||||
n := protowire.ConsumeFieldValue(tagNum, wireType, bz)
|
||||
if n < 0 {
|
||||
err = fmt.Errorf("could not consume field value for tagNum: %d, wireType: %q; %w",
|
||||
tagNum, wireTypeToString(wireType), protowire.ParseError(n))
|
||||
return hasUnknownNonCriticals, err
|
||||
}
|
||||
fieldBytes := bz[:n]
|
||||
bz = bz[n:]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user