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

psbt: Handle underflow on small key byte length

Public commit record

What the developer wrote

Authored by Mitchell Bagot

80/100 · Strong
psbt: Handle underflow on small key byte length

In PSBT keys, a change was recently introduced to allow for multi-byte
key type values. In this change, the key data length was changed to
calculate based on the total key length, subtracting the byte count of
the key type compact size value. For malformed PSBT inputs where the
total key length is insufficient to cover the type value compact size,
this causes an underflow in the subtraction, panicing on debug and
potentially causing incorrect behaviour for release.

Instead, this calculation should use a checked_sub, erroring gracefully
when this underflow would otherwise occur.

Change key data length calculation to use checked_sub and return an
InvalidKey error when the total key length value is invalid to parse
the key type correctly.
✓ Descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ Explains rationale or failure mode
The short version

What changed, and why it matters

This commit fixes a bug in how the library reads PSBT (Partially Signed Bitcoin Transaction) keys. A recent change accidentally made it possible for a malformed input to cause an arithmetic underflow when calculating how many bytes of key data remain. In debug builds that would panic (crash); in release builds it could wrap around and behave incorrectly. The fix uses a safe checked subtraction and returns a proper parsing error instead.

Recommended action

Apply the patch. It is a minimal, defensive fix. If running an affected version, avoid parsing untrusted PSBT data until patched, or ensure release builds are used where the impact is reduced to incorrect behavior rather than panic.

Security signals we found

01

Integer underflow in length calculation

02

Debug-build panic / potential release-build wraparound

03

Malformed input can trigger abnormal termination

04

PSBT parsing error path now returns InvalidKey instead of panicking

Risk score

Why this scored 65/100

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