From a1b9e741d4c49b79db94fb45e46034020350bdfb Mon Sep 17 00:00:00 2001 From: Romeo Rosete Date: Tue, 20 May 2025 11:00:33 -0400 Subject: [PATCH] Potential fix for code scanning alert no. 5: Size computation for allocation may overflow Romeo Rosete Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- common/hexutil/hexutil.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/hexutil/hexutil.go b/common/hexutil/hexutil.go index d3201850a8..d9b5721a21 100644 --- a/common/hexutil/hexutil.go +++ b/common/hexutil/hexutil.go @@ -82,6 +82,9 @@ func MustDecode(input string) []byte { // Encode encodes b as a hex string with 0x prefix. func Encode(b []byte) string { + if len(b) > (int(^uint(0) >> 1))/2 { + panic("input too large to encode as hex string") + } enc := make([]byte, len(b)*2+2) copy(enc, "0x") hex.Encode(enc[2:], b)