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

Merge bitcoin/bitcoin#35989: wallet: fix crash on importdescriptors with a range ending at 2^31-1

Public commit record

What the developer wrote

Authored by Ava Chow

96/100 · Strong
Merge bitcoin/bitcoin#35989: wallet: fix crash on importdescriptors with a range ending at 2^31-1

93c8aec3fbc8c5a2fcc834c4acc1b7d96bffa9a0 doc: add release note for #35989 (Shuvam Pandey)
457c9e8999fbee1d37f41eaede681f787e657395 script: avoid overflow when checking descriptor range bounds (Shuvam Pandey)
ab3bb55a67cced3551e8ebb658c4d962a10d3715 test: add coverage for descriptor range end bounds (Shuvam Pandey)
867ad9bffbd3ab26c9899207ddd11380e0c1a1bd wallet: fix integer overflow in descriptor keypool top up (Shuvam Pandey)
1889440f821d6bf8394050c96cc8e06a2f18d9c2 wallet: reject unrepresentable descriptor import ranges (Shuvam Pandey)

Pull request description:

`WalletDescriptor` stores an exclusive range end in `int32_t`. Importing
`[2147483647, 2147483647]` produces an end of `2^31`, which narrows to a negative
value and aborts the node during keypool top-up. An import without a range can
hit the same issue with an oversized `-keypool`.

Check the exclusive end before constructing the wallet descriptor, covering
both explicit and default ranges. The bound stays wallet-specific: scanning
RPCs still accept `INT32_MAX` as an inclusive endpoint.

Also calculate the keypool top-up endpoint in `int64_t` before checking its
bound, and reject reversed ranges before computing `high - low` in
`CheckDescriptorRangeBounds`. These fix the overflows reached by
`keypoolrefill INT32_MAX` after advancing a descriptor, and by `[INT64_MAX, 0]`,
respectively. Regression tests cover all three fixes.

I tested on macOS arm64 with Clang 22 and UBSan passed: 34 targeted unit
cases and the importdescriptors, keypool, deriveaddresses (RPC and CLI),
scantxoutset, and scanblocks functional tests.

ACKs for top commit:
achow101:
ACK 93c8aec3fbc8c5a2fcc834c4acc1b7d96bffa9a0
polespinasa:
ACK 93c8aec3fbc8c5a2fcc834c4acc1b7d96bffa9a0

Tree-SHA512: aec09a6e8d71ff1f57f8db6927fd93469e47f3549357dde4fceb3ef77f9c3be802c720d6856578149f78e5a277be8605477dbe9df7fd88555b4db355624cad0f
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context✓ 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 update fixes a crash in Bitcoin Core's wallet that could be triggered when importing a descriptor with a range ending at the largest 32-bit signed integer (2,147,483,647). Because the wallet stores the range end as an exclusive value in a 32-bit signed integer, that endpoint becomes 2^31 and wraps around to a negative number, causing the node to abort during keypool top-up. The patch rejects such unrepresentable ranges before they are stored, and also hardens related arithmetic to avoid similar overflows.

Recommended action

Apply the patch. Nodes accepting arbitrary wallet descriptor imports or using non-default -keypool values should upgrade, as the crash is reachable via RPC and can be triggered by a local wallet user or any caller with wallet RPC access.

Security signals we found

01

Integer overflow leading to signed truncation and node abort

02

Wallet RPC input validation bypass

03

Undefined behavior reachable through importdescriptors and keypoolrefill

04

Denial-of-service vector against wallet node

05

Regression tests added for all three overflow scenarios

Risk score

Why this scored 66/100

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