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

Merge rust-bitcoin/rust-bitcoin#6879: primitives: Fix Witness::get index overflow

Public commit record

What the developer wrote

Authored by Andrew Poelstra

96/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6879: primitives: Fix Witness::get index overflow

ca6bf03d0b41521327e9041104612aaf538ff703 primitives: Test Witness::get index overflow (Jamil Lambert, PhD)
fb0bbc1dd77da590f0ab94b166b41dd942a6410e primitives: Fix Witness::get index overflow (Jamil Lambert, PhD)

Pull request description:

`Witness::get` passes a caller-controlled index to `decode_cursor`, which computes `start_of_indices + index * 4` with unchecked arithmetic. A large index such as `usize::MAX / 4 + 1` overflows: with overflow checks off it wraps back to element 0's offset and returns the first element instead of `None`, and with them on it panics.

Use checked arithmetic so an out-of-range index returns `None`.

Closes project-loupe/audit-rust-bitcoin#159


ACKs for top commit:
apoelstra:
ACK ca6bf03d0b41521327e9041104612aaf538ff703; successfully ran local tests
tcharding:
ACK ca6bf03d0b41521327e9041104612aaf538ff703
satsfy:
tACK ca6bf03d0b41521327e9041104612aaf538ff703


Tree-SHA512: f6538c5d214b8fa935ce14896d31e33eab6e640160160e152a76be486b62971f042edfd83eb62f5d9ff6ce6ab59f516cef6c676ce7e39259ac5af72d4049ee51
✓ 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 commit fixes a bug in how the Bitcoin library reads items from a transaction witness. A function called Witness::get takes an index number from the caller and uses it to calculate a memory offset. With a very large index, the arithmetic could overflow, either returning the wrong witness item or causing the program to panic. The fix uses checked arithmetic so that any out-of-range index safely returns None. The bug was found during an external security audit.

Recommended action

Upgrade to a version of rust-bitcoin that includes this commit. If upgrading is not possible, avoid passing untrusted or unvalidated indices to Witness::get. No immediate incident response is required unless the application exposes witness indexing to untrusted input.

Security signals we found

01

Integer overflow in index calculation

02

Caller-controlled index used without bounds checking

03

Potential panic or incorrect data return from API

04

Fix uses checked arithmetic

05

Regression test added for overflow index

06

Linked to external audit finding

Risk score

Why this scored 51/100

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