From 19085392a26cbb7409d353d8d67e09a0b31242fa Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 14 Jan 2025 10:56:14 +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 f0c682cebd..d50903e4c1 100644 --- a/accounts/abi/type.go +++ b/accounts/abi/type.go @@ -153,6 +153,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 e6b08b4878..cd2577b793 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") + } +}