impose size limit for DecodeBytesExtraFields (#1637)

This commit is contained in:
Wanwiset Peerapatanapokin 2025-10-16 12:16:14 +04:00 committed by benjamin202410
parent 3fb7e4bb18
commit 4947b75c21

View file

@ -81,6 +81,11 @@ func DecodeBytesExtraFields(b []byte, val interface{}) error {
if len(b) == 0 {
return errors.New("extra field is 0 length")
}
// Prevent payload attack, limit the size of extra field to 20k bytes. Normal Extrafield payload is less than 7k bytes.
if len(b) > 20000 {
return errors.New("extra field is too long")
}
switch b[0] {
case 2:
return rlp.DecodeBytes(b[1:], val)