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

wire: clear transaction scripts on decode errors

Public commit record

What the developer wrote

Authored by Olaoluwa Osuntokun

78/100 · Adequate
wire: clear transaction scripts on decode errors

In this commit, we clear TxIn and TxOut before a failed public transaction decode releases its script arena. This prevents the partially decoded receiver from retaining slices into memory that later decodes can reuse, while keeping the block decoder's internal path unchanged.

The regression covers every truncated prefix in base and witness encodings with buffered and streaming readers, then checks a successful retry into the same receiver. We also inspect the internal decoder in the allocation-budget test so error cleanup cannot hide excessive reservations.
✓ 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 fixes a memory-safety bug in btcd's Bitcoin transaction decoder. When decoding a transaction failed partway through, the partially built transaction could still hold pointers to a shared memory area (an 'arena') used for scripts. That arena would then be reused for later decodes, meaning stale or attacker-controlled data could leak between unrelated transactions. The fix clears the transaction's inputs and outputs on any public decode error before returning the arena to the pool. The commit also adds tests covering every truncated prefix and both buffered and streaming readers.

Recommended action

Treat this as a security-relevant hardening fix. Review any code that reuses a MsgTx receiver after BtcDecode errors, and upgrade to a release containing this commit. No immediate remote exploit is demonstrated, but the stale-arena pattern is a real memory-safety risk in a network-facing parser.

Security signals we found

01

Use-after-free-like pattern: staged slices referencing a reusable arena after decode failure

02

Shared memory pool (script arena) reused across decodes

03

Potential information disclosure or memory corruption if stale arena-backed scripts are accessed

04

Fix is defensive cleanup on error path, not a change to successful decode behavior

05

Comprehensive regression tests for truncated prefixes and both buffered/streaming readers

Risk score

Why this scored 61/100

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