AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 61 Bitcoin

consensus: Add CompactSize range check to deserialization

Public commit record

What the developer wrote

Authored by Erick Cestari

83/100 · Strong
consensus: Add CompactSize range check to deserialization

Reject CompactSize values exceeding MAX_COMPACT_SIZE (0x02000000) during
deserialization, matching Bitcoin Core's serialize.h limit.

Extract read_compact_size logic into a private free function to allow
tests to bypass the range check when validating non-minimal encoding.

Add test for the new SizeTooLargeCompactSize error at the boundary.

Update bip152 error test to expect failure at deserialization rather
than at index computation, since the range check now triggers earlier.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification
The short version

What changed, and why it matters

This commit adds a safety limit when reading Bitcoin's 'CompactSize' numbers from serialized data. Before, a malformed message could claim an absurdly large number of elements (for example, billions of items in a list), which could be used to exhaust memory or trigger a panic. Now values above Bitcoin Core's documented maximum are rejected early during parsing. The change also refactors the parsing code so tests can still check non-minimal encoding without the new limit.

Recommended action

Review callers that previously handled large CompactSize values to ensure they tolerate the new error. Confirm that the internal test-only bypass (range_check=false) is not exposed to untrusted input paths. Consider fuzzing the CompactSize decoder around the 0x02000000 boundary and the non-minimal encoding cases.

Security signals we found

01

Adds an upper-bound check to a length-prefix decoder

02

Aligns with Bitcoin Core's documented MAX_COMPACT_SIZE limit

03

Prevents oversized vector/element allocation claims during deserialization

04

Introduces a new explicit error variant for oversized CompactSize values

05

Moves error detection earlier in the deserialization pipeline

Risk score

Why this scored 61/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 12/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.