Skip to content

Commit

Permalink
Add bound check to abi encoder (#205)
Browse files Browse the repository at this point in the history
* Add bound check to abi encoder

* Add changelog
  • Loading branch information
ferranbt committed Jun 13, 2022
1 parent f6037f0 commit d96bb6f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

# 0.1.2 (Unreleased)

- Fix out-of-bounds reading of bytes during ABI decoding [[GH-205](https://github.com/umbracle/ethgo/issues/205)]
- Update `fastrlp` to `59d5dd3` commit to fix a bug on bytes length check [[GH-204](https://github.com/umbracle/ethgo/issues/204)]
- Update `btcd` library to new `v0.22.1`
- Add option in `contract` to send transactions with EIP-1559 [[GH-198](https://github.com/umbracle/ethgo/issues/198)]
Expand Down
8 changes: 8 additions & 0 deletions abi/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ func decodeTuple(t *Type, data []byte) (interface{}, []byte, error) {
orig := data
origLen := len(orig)
for indx, arg := range t.tuple {
if len(data) < 32 {
return nil, nil, fmt.Errorf("incorrect length")
}

entry := data
if arg.Elem.isDynamicType() {
offset, err := readOffset(data, origLen)
Expand Down Expand Up @@ -225,6 +229,10 @@ func decodeArraySlice(t *Type, data []byte, size int) (interface{}, []byte, erro
for indx := 0; indx < size; indx++ {
isDynamic := t.elem.isDynamicType()

if len(data) < 32 {
return nil, nil, fmt.Errorf("incorrect length")
}

entry := data
if isDynamic {
offset, err := readOffset(data, origLen)
Expand Down
8 changes: 8 additions & 0 deletions abi/decode_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package abi

import "testing"

func TestDecode_BytesBound(t *testing.T) {
typ := MustNewType("tuple(string)")
decodeTuple(typ, nil) // it should not panic
}

1 comment on commit d96bb6f

@vercel
Copy link

@vercel vercel bot commented on d96bb6f Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.