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

primitives: Avoid allocating claimed size when decoding witness length

Public commit record

What the developer wrote

Authored by jrakibi

73/100 · Adequate
primitives: Avoid allocating claimed size when decoding witness length

Avoid allocating the claimed size when decoding witness length.

It's currently possible to claim a length and have the decoder
reserve up to `MAX_VECTOR_ALLOCATE` before any data bytes have
arrived, just from reading the length prefix.

Instead, we can reserve only the prefix, and let the buffer grow incrementally
as bytes arrive.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This change fixes a memory allocation quirk in how Bitcoin transaction witness data is decoded. Previously, when reading a witness element, the decoder would reserve memory equal to the full claimed size of the element immediately, even though no actual element bytes had been read yet. The patch makes it reserve only a small minimum amount and let the buffer grow as real data arrives. This reduces the risk of an attacker causing large memory reservations by supplying a misleading length prefix, though the actual allocation still cannot exceed a built-in maximum.

Recommended action

Treat as a low-to-moderate hardening fix. Review whether MAX_VECTOR_ALLOCATE and MIN_VECTOR_ALLOCATE constants are documented and whether other decoders in the crate use the same pattern. No immediate emergency response is indicated, but backporting to stable branches is reasonable if witness parsing is exposed to untrusted network data.

Security signals we found

01

Memory allocation based on attacker-controlled length prefix

02

Decoder reserves claimed full size before payload bytes arrive

03

Potential memory pressure / small-allocation DoS vector

04

Bounds/vector allocation hardening in deserialization code

Risk score

Why this scored 51/100

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