diff options
author | Janos Guljas <janos@resenje.org> | 2018-02-23 01:50:47 +0800 |
---|---|---|
committer | Janos Guljas <janos@resenje.org> | 2018-02-23 01:51:34 +0800 |
commit | 6a9730edaa3c398ef1e9fe084f9b16de4d3ef78e (patch) | |
tree | 442ae3e5d75fa5418b362474754d319a7fdfa8f0 /accounts/abi/unpack.go | |
parent | a3a07350dcef0ba39829a20d8ddba4bd3463d293 (diff) | |
parent | 221486a29109803286c1448426d6180ef5024cf0 (diff) | |
download | dexon-6a9730edaa3c398ef1e9fe084f9b16de4d3ef78e.tar dexon-6a9730edaa3c398ef1e9fe084f9b16de4d3ef78e.tar.gz dexon-6a9730edaa3c398ef1e9fe084f9b16de4d3ef78e.tar.bz2 dexon-6a9730edaa3c398ef1e9fe084f9b16de4d3ef78e.tar.lz dexon-6a9730edaa3c398ef1e9fe084f9b16de4d3ef78e.tar.xz dexon-6a9730edaa3c398ef1e9fe084f9b16de4d3ef78e.tar.zst dexon-6a9730edaa3c398ef1e9fe084f9b16de4d3ef78e.zip |
swarm, cmd/swarm: Merge branch 'master' into multiple-ens-endpoints
Diffstat (limited to 'accounts/abi/unpack.go')
-rw-r--r-- | accounts/abi/unpack.go | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/accounts/abi/unpack.go b/accounts/abi/unpack.go index 80efb3f7e..761c80edf 100644 --- a/accounts/abi/unpack.go +++ b/accounts/abi/unpack.go @@ -1,4 +1,4 @@ -// Copyright 2015 The go-ethereum Authors +// Copyright 2017 The go-ethereum Authors // This file is part of the go-ethereum library. // // The go-ethereum library is free software: you can redistribute it and/or modify @@ -95,6 +95,9 @@ func readFixedBytes(t Type, word []byte) (interface{}, error) { // iteratively unpack elements func forEachUnpack(t Type, output []byte, start, size int) (interface{}, error) { + if size < 0 { + return nil, fmt.Errorf("cannot marshal input to array, size is negative (%d)", size) + } if start+32*size > len(output) { return nil, fmt.Errorf("abi: cannot marshal in to go array: offset %d would go over slice boundary (len=%d)", len(output), start+32*size) } @@ -181,16 +184,32 @@ func toGoType(index int, t Type, output []byte) (interface{}, error) { // interprets a 32 byte slice as an offset and then determines which indice to look to decode the type. func lengthPrefixPointsTo(index int, output []byte) (start int, length int, err error) { - offset := int(binary.BigEndian.Uint64(output[index+24 : index+32])) - if offset+32 > len(output) { - return 0, 0, fmt.Errorf("abi: cannot marshal in to go slice: offset %d would go over slice boundary (len=%d)", len(output), offset+32) + bigOffsetEnd := big.NewInt(0).SetBytes(output[index : index+32]) + bigOffsetEnd.Add(bigOffsetEnd, common.Big32) + outputLength := big.NewInt(int64(len(output))) + + if bigOffsetEnd.Cmp(outputLength) > 0 { + return 0, 0, fmt.Errorf("abi: cannot marshal in to go slice: offset %v would go over slice boundary (len=%v)", bigOffsetEnd, outputLength) } - length = int(binary.BigEndian.Uint64(output[offset+24 : offset+32])) - if offset+32+length > len(output) { - return 0, 0, fmt.Errorf("abi: cannot marshal in to go type: length insufficient %d require %d", len(output), offset+32+length) + + if bigOffsetEnd.BitLen() > 63 { + return 0, 0, fmt.Errorf("abi offset larger than int64: %v", bigOffsetEnd) } - start = offset + 32 - //fmt.Printf("LENGTH PREFIX INFO: \nsize: %v\noffset: %v\nstart: %v\n", length, offset, start) + offsetEnd := int(bigOffsetEnd.Uint64()) + lengthBig := big.NewInt(0).SetBytes(output[offsetEnd-32 : offsetEnd]) + + totalSize := big.NewInt(0) + totalSize.Add(totalSize, bigOffsetEnd) + totalSize.Add(totalSize, lengthBig) + if totalSize.BitLen() > 63 { + return 0, 0, fmt.Errorf("abi length larger than int64: %v", totalSize) + } + + if totalSize.Cmp(outputLength) > 0 { + return 0, 0, fmt.Errorf("abi: cannot marshal in to go type: length insufficient %v require %v", outputLength, totalSize) + } + start = int(bigOffsetEnd.Uint64()) + length = int(lengthBig.Uint64()) return } |