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>
This commit is contained in:
Romeo Rosete 2025-05-20 11:06:54 -04:00 committed by GitHub
parent def873259a
commit a32388b614
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)