internal/ethapi: pad string before checking length

This commit is contained in:
lightclient 2025-09-26 07:09:58 -06:00
parent f9580983e7
commit dc0fbc26d8
No known key found for this signature in database
GPG key ID: 657913021EF45A6A

View file

@ -446,12 +446,12 @@ 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
} }
if len(s) > 64 {
return common.Hash{}, len(s) / 2, errors.New("hex string too long, want at most 32 bytes")
}
b, err := hex.DecodeString(s) b, err := hex.DecodeString(s)
if err != nil { if err != nil {
return common.Hash{}, 0, errors.New("hex string invalid") return common.Hash{}, 0, errors.New("hex string invalid")