bitcoin-dev

ReadCompactSize without range check

ReadCompactSize without range check

Original Postby Tobin Harding

Posted on: September 2, 2024 23:18 UTC

The ReadCompactSize function, as defined in serialize.h, includes an optional range_check parameter that is set to true by default.

This setting ensures that the value read by the function does not exceed 0x02000000, effectively enforcing a limit that keeps the compact size value within the bounds of a 32-bit unsigned integer. An examination of the codebase reveals that there are no instances where ReadCompactSize is invoked with the range_check parameter set to false. This information raises a pertinent inquiry regarding the necessity of adhering to the constraints of a 32-bit integer for values encoded using CompactSize, and questions the utility of the 0xFF or 9-byte encoding scheme for compact sizes, suggesting a potential reevaluation of whether this approach remains necessary.