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

bitcoin: Lower initial allocation for Vec Decoder

Public commit record

What the developer wrote

Authored by Mitchell Bagot

76/100 · Adequate
bitcoin: Lower initial allocation for Vec Decoder

In the implementation of consensus_decode_from_finite_reader for Vec<T>,
the initial vector capacity is calculated as 4_000_000 / 4 / sizeof<T>.
This is an arbitrary value that doesn't provide any specific benefit,
per discussion in #4797. Fedimint has a similar implementation of the
function using different, lower values.

Change the initial allocation capacity to match Fedimint's.
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit reduces the initial memory allocation when decoding a variable-length list (Vec) from Bitcoin protocol data. Previously, the code could reserve a large chunk of memory based on an untrusted length value, which could be abused to waste or exhaust memory. The new code caps the initial reservation to roughly 8,000 bytes worth of elements and grows the vector only as items are actually read. This is a hardening change against denial-of-service via maliciously large length fields.

Recommended action

Treat as a security hardening patch. Review whether other Decodable collection types (e.g., Box<[T]>, custom containers) use similar upfront allocation based on untrusted lengths and apply consistent caps. Consider adding regression tests with oversized compact-size length fields.

Security signals we found

01

Untrusted length value used for memory allocation

02

Initial vector capacity capped to limit memory reservation

03

OOM protection mentioned in code comment

04

Change motivated by denial-of-service hardening

Risk score

Why this scored 42/100

Our methodology →
Potential impact 8/30
Exploitability 7/25
Stealth signal 6/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.