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

Merge rust-bitcoin/rust-bitcoin#6763: bip152: validate prefill count before allocating short IDs

Public commit record

What the developer wrote

Authored by Andrew Poelstra

96/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6763: bip152: validate prefill count before allocating short IDs

7f80030897591c1d3bcf5023fe24d78115034403 bip152: test excessive prefill indexes (racequite)
cf94409eb486fd20e404acca67e87ccec6f1ebb4 bip152: validate prefill count before allocating short IDs (racequite)

Pull request description:

`HeaderAndShortIds::from_block` documents that invalid prefill indexes return `Error::InvalidPrefill`. However, it calculated the short ID capacity using unchecked subtraction before validating the input.

When the number of prefill indexes exceeds the number of transactions, this subtraction panics with overflow checks enabled. Other build configurations may wrap the subtraction and attempt an invalid or excessively large allocation.

Use `checked_sub` to return `Error::InvalidPrefill` before allocating the short ID vector. Add a regression test covering a single-transaction block with too many prefill indexes.


ACKs for top commit:
apoelstra:
ACK 7f80030897591c1d3bcf5023fe24d78115034403; successfully ran local tests


Tree-SHA512: 22d77e24df00332016107c482ae68c16fcdea387fa5fd4e5675d2e90c9067a4c1a961b6a9523bc58c99260f1011ae12e30e034881c7c2ccdb45f68972b948a9c
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference✓ Names security-relevant behavior explicitly
The short version

What changed, and why it matters

This change fixes a panic/crash bug in Bitcoin compact block (BIP152) encoding. When a caller asked to 'prefill' more transactions than actually exist in the block, the code subtracted the two numbers without checking, which could cause the program to panic (in safe builds) or try to allocate a nonsensical amount of memory (in other builds). The patch validates the count first and returns a proper error instead.

Recommended action

Merge the patch; it is a small, defensive fix with a regression test. Review other similar `with_capacity` arithmetic in the P2P module for the same pattern.

Security signals we found

01

Integer underflow in capacity calculation

02

Panic / denial-of-service via malformed input

03

Potential uncontrolled memory allocation

04

Violation of documented error contract

05

Missing input validation before resource allocation

Risk score

Why this scored 57/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 5/15
Affected reach 8/15
Confidence 9/10
Evidence quality 5/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.