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#6858: base58: saturate the reserve len multiplication

Public commit record

What the developer wrote

Authored by Andrew Poelstra

100/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6858: base58: saturate the reserve len multiplication

898da6ed12fcef49180d4b622d1a0a4dd5850f3d base58: saturate the reserve len multiplication (satsfy (Renato Britto))

Pull request description:

Use a `saturating_mul()` to handle overflows on `encoded_reserve_len`.

Didn't think this was worth a test because of the input needed to overflow this isn't allocatable on 64-bit and debug already catches it, so this is just fixing the release wrap.

Per https://github.com/project-loupe/audit-rust-bitcoin/issues/60

_This finding was discovered by [Project Loupe](https://github.com/project-loupe/loupe)._


ACKs for top commit:
apoelstra:
ACK 898da6ed12fcef49180d4b622d1a0a4dd5850f3d; successfully ran local tests


Tree-SHA512: 399b3e503a800de672ce8661b014d9ea2b60081ea427701542736f1e511167195a9c38415fe028edfe556d5f7961566f52580fa61c2941abe0a1d96a3e490779
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode✓ 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 tiny but real arithmetic bug in the library's base58 string encoder. When asked to reserve memory for an extremely large encoded string, the old code could multiply two numbers together and silently wrap around to a small value on release builds (integer overflow), causing the program to reserve far less memory than needed and then write past the end. The fix uses saturating multiplication so the value stays at the maximum safe size instead of wrapping. The practical impact is limited because the input sizes needed to trigger this are not realistically allocatable on 64-bit systems, and debug builds already panic on overflow.

Recommended action

No immediate action beyond applying the patch. Users on current releases should update when convenient. Developers should consider adding a regression test for the overflow edge case even though the reporter deemed it impractical, and audit similar reserve_len-style calculations elsewhere in the crate for the same pattern.

Security signals we found

01

Integer overflow in buffer-size calculation

02

Potential heap buffer overrun due to undersized allocation

03

Release-build-only wraparound (debug builds already panic)

04

Third-party security audit finding (Project Loupe)

05

Saturating arithmetic used as fix

Risk score

Why this scored 37/100

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