Skip to content

Commit 2e2fece

Browse files
ethapi: reject oversize storage keys before hex decode (#32750)
Bail out of decodeHash when the raw hex string is longer than 32 byte before actually decoding. --------- Co-authored-by: lightclient <[email protected]>
1 parent a8f7965 commit 2e2fece

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

internal/ethapi/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,13 +449,13 @@ func decodeHash(s string) (h common.Hash, inputLength int, err error) {
449449
if (len(s) & 1) > 0 {
450450
s = "0" + s
451451
}
452+
if len(s) > 64 {
453+
return common.Hash{}, len(s) / 2, errors.New("hex string too long, want at most 32 bytes")
454+
}
452455
b, err := hex.DecodeString(s)
453456
if err != nil {
454457
return common.Hash{}, 0, errors.New("hex string invalid")
455458
}
456-
if len(b) > 32 {
457-
return common.Hash{}, len(b), errors.New("hex string too long, want at most 32 bytes")
458-
}
459459
return common.BytesToHash(b), len(b), nil
460460
}
461461

0 commit comments

Comments
 (0)