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

Merge rust-bitcoin/rust-bitcoin#6819: Remove panics from `LegacyPublicKey::from_str`

Public commit record

What the developer wrote

Authored by Andrew Poelstra

91/100 · Strong
Merge rust-bitcoin/rust-bitcoin#6819: Remove panics from `LegacyPublicKey::from_str`

e9eebc4a49e32d157f1372c8f895243fba7cda4d Remove panics from `LegacyPublicKey::from_str` (Martin Habovstiak)

Pull request description:

While the implementation was correct the lack of panics was not obvious from the code. This rewrites it to be completely panic-free.


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


Tree-SHA512: 353cf2043d059f2e120bd49eb88c83d0a3cde451a805f9f34bafd0bdc1641ffc17b4e000e1be9ff817a740fe48f3456598ec85e3941481a81ca0c6b6e66bfe5c
✓ 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 change refactors how a Bitcoin public key is parsed from a text string so that the code no longer relies on 'this should never happen' assumptions that could trigger a program crash. The old code only accepted two exact string lengths and used an internal 'unreachable' panic for any other length error. The new code tries the two valid lengths directly and returns a proper error instead of panicking. It is a defensive hardening fix rather than a confirmed exploitable vulnerability.

Recommended action

Treat as a low-risk hardening improvement. Review downstream callers to ensure they handle ParsePublicKeyError rather than relying on panics, and consider auditing other FromStr implementations for similar unreachable! assumptions.

Security signals we found

01

Removal of unreachable! panic branches in parsing code

02

Defensive refactor to make panic-freedom locally obvious

03

Improved error handling for malformed input lengths

04

No change to accepted valid inputs or public API semantics

Risk score

Why this scored 27/100

Our methodology →
Potential impact 5/30
Exploitability 3/25
Stealth signal 4/15
Affected reach 6/15
Confidence 6/10
Evidence quality 3/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.