ethapi: reject oversize storage keys before hex decode

This commit is contained in:
Matus Kysel 2025-09-26 12:24:39 +02:00
parent b1eb33ce8b
commit f9580983e7
No known key found for this signature in database
GPG key ID: D39B599A02ADE173

View file

@ -446,6 +446,9 @@ func decodeHash(s string) (h common.Hash, inputLength int, err error) {
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") { if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
s = s[2:] s = s[2:]
} }
if len(s) > 64 { // 32 bytes
return common.Hash{}, len(s) / 2, errors.New("hex string too long, want at most 32 bytes")
}
if (len(s) & 1) > 0 { if (len(s) & 1) > 0 {
s = "0" + s s = "0" + s
} }
@ -453,9 +456,6 @@ func decodeHash(s string) (h common.Hash, inputLength int, err error) {
if err != nil { if err != nil {
return common.Hash{}, 0, errors.New("hex string invalid") return common.Hash{}, 0, errors.New("hex string invalid")
} }
if len(b) > 32 {
return common.Hash{}, len(b), errors.New("hex string too long, want at most 32 bytes")
}
return common.BytesToHash(b), len(b), nil return common.BytesToHash(b), len(b), nil
} }