alloy-rlp v0.1.0 (higher version are also affected)
Operating System
None
Describe the bug
When deriving Encodable::length, the underlying function alloy_rlp::length_of_length uses the hard-coded value of 8 for the number of bytes in a usize. However, on a 32-bit target, this is incorrect. In certain cases, this results in invalid encodings on 32-bit targets.
Using the correct number of bytes by changing the affected line to the following fixes this problem:
1 + (usize::BITS as usize / 8) - payload_length.leading_zeros() as usize / 8
Of course, if it would be helpful in any way, I can also create a PR for this tiny fix.
Component
rlp
What version of Alloy are you on?
alloy-rlp v0.1.0 (higher version are also affected)
Operating System
None
Describe the bug
When deriving
Encodable::length
, the underlying functionalloy_rlp::length_of_length
uses the hard-coded value of8
for the number of bytes in ausize
. However, on a 32-bit target, this is incorrect. In certain cases, this results in invalid encodings on 32-bit targets.Using the correct number of bytes by changing the affected line to the following fixes this problem:
Of course, if it would be helpful in any way, I can also create a PR for this tiny fix.