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

Merge rust-bitcoin/rust-bitcoin#6897: consensus_encoding: fix overcounting bug in the composite encoders exact size len calculation

Public commit record

What the developer wrote

Authored by Andrew Poelstra

91/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6897: consensus_encoding: fix overcounting bug in the composite encoders exact size len calculation

914365b43c95aa63568da54acf12edc3fe7b8e9a consensus_encoding: fix bug in the composite encoder's exact size (Nick Johnson)

Pull request description:

The `ExactSizeEncoder::len` contract states that it should return the number of bytes *remaining* in the encoder. However, the composite encoders (e.g. `Encoder2`) return a static, total amount. This fix only returns amounts for non-finished sub-encoders.

nymius found this issue while hacking on rust-psbt.


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


Tree-SHA512: ee23300a5bc42210ba071766b389203ac353db326083383498144e670498831a308cb770a691a257230443214a3bd9af7e529073778db03b8b20959b2958ebcc
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Mentions testing or verification✓ Links an issue, advisory, or supporting reference
The short version

What changed, and why it matters

This commit fixes a counting bug in a Rust Bitcoin library. The library has combined encoders that bundle multiple pieces of data together. A method called len() is supposed to report how many bytes are left to encode, but it was incorrectly reporting the total size of all pieces even after some pieces were already processed. The fix makes it only count the pieces that have not yet been processed. The bug could cause callers that rely on len() for buffer sizing or progress checks to over-allocate or misjudge remaining work, but it is a correctness fix rather than a clear-cut security vulnerability.

Recommended action

Upgrade to a version of rust-bitcoin consensus_encoding that includes this fix. If you maintain downstream code that calls ExactSizeEncoder::len() on composite encoders, review any logic that used the previous overcounted value for buffer allocation, serialization bounds, or progress tracking. No immediate exploit is evident, but correctness-sensitive consensus code should not rely on violated contracts.

Security signals we found

01

Violation of documented API contract (ExactSizeEncoder::len)

02

Potential incorrect buffer-size or progress decisions by downstream callers

03

Composite encoder state not fully isolated in size reporting before fix

04

Regression test added to prevent reintroduction

Risk score

Why this scored 37/100

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