Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unknownproto: check result from protowire.ConsumeFieldValue and return an error #7770

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b915e8d
unknownproto: check result from protowire.ConsumeFieldValue and retur…
odeke-em Nov 1, 2020
4499515
Address AlexanderBez's suggestions
odeke-em Nov 1, 2020
0b9228e
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
odeke-em Nov 2, 2020
8c41652
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
odeke-em Nov 2, 2020
5c8e5fe
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
odeke-em Nov 2, 2020
be8f101
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
odeke-em Nov 3, 2020
696bbc7
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
odeke-em Nov 3, 2020
77675a2
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
odeke-em Nov 4, 2020
d45adf0
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
odeke-em Nov 4, 2020
5fe44eb
Use require in tests
odeke-em Nov 4, 2020
9f6f7e2
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
odeke-em Nov 5, 2020
27341b2
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
odeke-em Nov 6, 2020
9b2a363
Add issue #7846 to TODO
odeke-em Nov 6, 2020
24071e7
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
mergify[bot] Nov 7, 2020
9c3a13e
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
mergify[bot] Nov 9, 2020
a380e5f
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
mergify[bot] Nov 9, 2020
fa8ba35
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
mergify[bot] Nov 9, 2020
36b21c7
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
mergify[bot] Nov 9, 2020
e4d0e8c
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
mergify[bot] Nov 9, 2020
018f3da
Merge branch 'master' into unknownproto-catch-errors-from-protowire.C…
mergify[bot] Nov 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions codec/unknownproto/regression_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package unknownproto_test

import (
"encoding/hex"
"io"
"testing"

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/simapp"
)

// Issue #7739: Catch parse errors resulting from unexpected EOF in
// protowire.ConsumeFieldValue. Discovered from fuzzing.
func TestBadBytesPassedIntoDecoder(t *testing.T) {
data, _ := hex.DecodeString("0A9F010A9C200A2D2F6962632E636F72652E636F6E6E656374696F6E2E76312E4D7367436F6E6E656374696F584F75656E496E6974126B0A0D6962637A65726F636C69656E74120B6962637A65726F636F6E6E1A1C0A0C6962636F6E65636C69656E74120A6962636F6E65636F6E6E00002205312E302E302A283235454635364341373935313335453430393336384536444238313130463232413442453035433212080A0612040A0208011A40143342993E25DA936CDDC7BE3D8F603CA6E9661518D536D0C482E18A0154AA096E438A6B9BCADFCFC2F0D689DCCAF55B96399D67A8361B70F5DA13091E2F929")
cfg := simapp.MakeTestEncodingConfig()
decoder := cfg.TxConfig.TxDecoder()
tx, err := decoder(data)

// TODO: File an issue to ensure that sdkerrors.Wrap(sdkerrors.ErrTxDecode, err.Error())
odeke-em marked this conversation as resolved.
Show resolved Hide resolved
// properly wraps errors to be compatible with errors.Is, otherwise right now it doesn't work correctly.

require.Contains(t, err.Error(), io.ErrUnexpectedEOF.Error())
require.Nil(t, tx)
}
5 changes: 5 additions & 0 deletions codec/unknownproto/unknown_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]

Expand Down