From 8578eb2fe1071c70eeee1a76b14d87e93ba129ca Mon Sep 17 00:00:00 2001 From: zhiqiangxu <652732310@qq.com> Date: Tue, 1 Nov 2022 21:28:40 +0800 Subject: [PATCH] accounts/abi: return error on fixed bytes with size larger than 32 bytes (#26075) * fixed bytes with size larger than 32 bytes is not allowed * add testcase --- accounts/abi/type.go | 3 +++ accounts/abi/type_test.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/accounts/abi/type.go b/accounts/abi/type.go index 008b665b1a..7f74907a84 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -154,6 +154,9 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty if varSize == 0 { typ.T = BytesTy } else { + if varSize > 32 { + return Type{}, fmt.Errorf("unsupported arg type: %s", t) + } typ.T = FixedBytesTy typ.Size = varSize } diff --git a/accounts/abi/type_test.go b/accounts/abi/type_test.go index 8c3aedca6a..a72531ba27 100644 --- a/accounts/abi/type_test.go +++ b/accounts/abi/type_test.go @@ -366,3 +366,10 @@ func TestGetTypeSize(t *testing.T) { } } } + +func TestNewFixedBytesOver32(t *testing.T) { + _, err := NewType("bytes4096", "", nil) + if err == nil { + t.Errorf("fixed bytes with size over 32 is not spec'd") + } +}