aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi
diff options
context:
space:
mode:
authorMartin Holst Swende <martin@swende.se>2018-02-02 21:03:58 +0800
committerMartin Holst Swende <martin@swende.se>2018-02-21 19:27:50 +0800
commit61f2279bdeac595a4607080028715a8222db6cd4 (patch)
treeb094853d3a8af19fa75ac71d55e269dd60589e12 /accounts/abi
parentbd6ed23899c8a3b4b6d0db29f0f6298e492cedd6 (diff)
downloadgo-tangerine-61f2279bdeac595a4607080028715a8222db6cd4.tar
go-tangerine-61f2279bdeac595a4607080028715a8222db6cd4.tar.gz
go-tangerine-61f2279bdeac595a4607080028715a8222db6cd4.tar.bz2
go-tangerine-61f2279bdeac595a4607080028715a8222db6cd4.tar.lz
go-tangerine-61f2279bdeac595a4607080028715a8222db6cd4.tar.xz
go-tangerine-61f2279bdeac595a4607080028715a8222db6cd4.tar.zst
go-tangerine-61f2279bdeac595a4607080028715a8222db6cd4.zip
abi: fix missing method on go 1.7/1.8
Diffstat (limited to 'accounts/abi')
-rw-r--r--accounts/abi/unpack.go36
1 files changed, 23 insertions, 13 deletions
diff --git a/accounts/abi/unpack.go b/accounts/abi/unpack.go
index 51fb9ab9b..761c80edf 100644
--- a/accounts/abi/unpack.go
+++ b/accounts/abi/unpack.go
@@ -184,22 +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) {
- offsetBig := big.NewInt(0).SetBytes(output[index : index+32])
- if !offsetBig.IsInt64() {
- return 0, 0, fmt.Errorf("abi offset larger than int64: %v", offsetBig)
+ 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)
}
- offset := int(offsetBig.Int64())
- 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)
+
+ if bigOffsetEnd.BitLen() > 63 {
+ return 0, 0, fmt.Errorf("abi offset larger than int64: %v", bigOffsetEnd)
}
- lengthBig := big.NewInt(0).SetBytes(output[offset : offset+32])
- if !lengthBig.IsInt64() {
- return 0, 0, fmt.Errorf("abi length larger than int64: %v", lengthBig)
+
+ 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)
}
- length = int(lengthBig.Int64())
- 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 totalSize.Cmp(outputLength) > 0 {
+ return 0, 0, fmt.Errorf("abi: cannot marshal in to go type: length insufficient %v require %v", outputLength, totalSize)
}
- start = offset + 32
+ start = int(bigOffsetEnd.Uint64())
+ length = int(lengthBig.Uint64())
return
}