core/types: fix problem decoding short typed tx

If kind == rlp.Byte, the size reported by Stream.Kind will be zero, but we need a buffer
of size 1 for ReadBytes. Since typed txs always have to be longer than 1 byte, we can just
return an error for kind == rlp.Byte.
This commit is contained in:
Felix Lange 2023-08-22 19:37:14 +02:00
parent c84ffe7d0f
commit b3f9f7b337
2 changed files with 4 additions and 0 deletions

View file

@ -165,6 +165,8 @@ func (r *Receipt) DecodeRLP(s *rlp.Stream) error {
}
r.Type = LegacyTxType
return r.setFromRLP(dec)
case kind == rlp.Byte:
return errShortTypedReceipt
default:
// It's an EIP-2718 typed tx receipt.
b, buf, err := getPooledBuffer(size)

View file

@ -145,6 +145,8 @@ func (tx *Transaction) DecodeRLP(s *rlp.Stream) error {
tx.setDecoded(&inner, rlp.ListSize(size))
}
return err
case kind == rlp.Byte:
return errShortTypedTx
default:
// It's an EIP-2718 typed TX envelope.
// First read the tx payload bytes into a temporary buffer.