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

Merge rust-bitcoin/rust-bitcoin#6781: base58: Use `div_ceil` for reserve length calculation

Public commit record

What the developer wrote

Authored by Andrew Poelstra

100/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6781: base58: Use `div_ceil` for reserve length calculation

196c27161d1e6e4d76b4be5978a7c45a864c96a6 Add regression test for reserve length calculation (Mitchell Bagot)
5b3cc125fdb6d015e0ddf14306dd7810a9110552 base58: Use div_ceil for reserve length calculation (Mitchell Bagot)

Pull request description:

When determining the size needed for an encoding buffer, the code currently uses an approximation by multiplying the payload length by 1.37. However, as this is done with integer operations, the value is rounded down, which for some payload lengths (namely 94), the encoding can panic due to an undersized buffer.

Use div_ceil for reserve length calculation to prevent panic on 94 byte encode.


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


Tree-SHA512: d0e737115211799874efecb1229885ddefae941a9132df3e19ea1f40f6c0c0c5238d42224a194b215e9657cb649b80c8511e4540029b5499a6f70cd254f71866
✓ 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
The short version

What changed, and why it matters

This commit fixes a bug in the base58 encoding function used for Bitcoin-style addresses. When encoding certain payload sizes (specifically 94 bytes), the program could panic because it reserved a buffer that was slightly too small. The fix rounds the buffer-size calculation up instead of down, preventing the crash. The commit also adds a regression test using a 90-byte payload with checksum (which triggers the same rounding edge case).

Recommended action

No immediate action beyond applying the patch; users relying on base58 encoding of large or adversarially chosen payloads should update. Review whether any other length-estimation helpers in the crate use similar integer-division patterns.

Security signals we found

01

Integer truncation leading to undersized buffer allocation

02

Potential panic in encoding path (denial-of-service vector)

03

Regression test added for the edge-case payload length

Risk score

Why this scored 46/100

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