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

Merge rust-bitcoin/rust-bitcoin#6919: Sanitize serde size hints before allocating

Public commit record

What the developer wrote

Authored by Andrew Poelstra

100/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6919: Sanitize serde size hints before allocating

f7c0ee459ed33fdade8977392f31bd8793e59d1a primitives: test witness size hint not trusted (satsfy (Renato Britto))
c48822a119e578d7a78ff8a16e6629d56cbec5db primitives: cap witness serde size hint for alloc (satsfy (Renato Britto))
91ff405a6318dac5051ee77c20e555ee7fdf33ff units: test serde size hints not trusted (satsfy (Renato Britto))
d4f03724d3b5fbaf073bf033361a65617f5ad71f units: cap serde size hints before preallocating (satsfy (Renato Britto))
803aff152959368852dd6bfd7f390ad5dff97833 internals: add cautious serde size hint (satsfy (Renato Britto))

Pull request description:

Close https://github.com/project-loupe/audit-rust-bitcoin/issues/11
Close https://github.com/project-loupe/audit-rust-bitcoin/issues/21
Close https://github.com/project-loupe/audit-rust-bitcoin/issues/127
Close https://github.com/project-loupe/audit-rust-bitcoin/issues/202

It was possible to feed massive alloc requests via the size hint of vec deserializers that comes directly from untrusted sources into units and primitives. The deserialized `SeqAccess::size_hint` value fed straight into `Vec::with_capacity`. A few bytes could request a huge allocation before anything was read.

This condition enables panics with a capacity overflow message or process abortions for excessive memory usage in downstream rust-bitcoin users using length prefixed formats (bincode, postcard, CBOR...).

This PR added a shared helper in `internals`, because of the universal applicability and to use both on units or primitives. I reviewed every hint size alloc and only found those primitives and units cases to be eligible for this fix.

Additionally, I found another instance on p2p, same class of bug, but it is out of scope because it is a consensus decoder, not serde.


ACKs for top commit:
apoelstra:
ACK f7c0ee459ed33fdade8977392f31bd8793e59d1a; successfully ran local tests
tcharding:
ACK f7c0ee459ed33fdade8977392f31bd8793e59d1a


Tree-SHA512: e11c71c7a3a12a627a528852cefe5d0469c55bd95fb370a11c688df921ad2af69c6f6b66371c68d756066994d8511673a3d966e6590254c72e104b2803636390
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ 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 commit fixes a denial-of-service weakness in how the library deserializes lists of Bitcoin data (witnesses, amounts, fee rates) from untrusted input. Before the fix, a few bytes of attacker-controlled data could claim a list would contain billions of items, causing the program to reserve a huge block of memory and crash or be killed. The patch caps how much memory is reserved up front, matching a well-known safeguard used by the serde library itself.

Recommended action

Upgrade to a release containing this merge commit. If you maintain downstream code that deserializes rust-bitcoin types from length-prefixed formats (bincode, postcard, CBOR, etc.), ensure you are on the patched version. No other immediate action is required; the fix is self-contained and includes regression tests.

Security signals we found

01

Untrusted serde size hint fed directly into Vec::with_capacity

02

Potential memory exhaustion / OOM kill from small malicious input

03

Denial-of-service vector in deserialization paths

04

Fix mirrors serde's own 1 MiB preallocation cap

05

Regression tests simulate maximum possible size hint

Risk score

Why this scored 70/100

Our methodology →
Potential impact 18/30
Exploitability 16/25
Stealth signal 10/15
Affected reach 12/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.