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

Merge bitcoin/bitcoin#36339: wallet: avoid int overflow in listtransactions

Public commit record

What the developer wrote

Authored by merge-script

96/100 · Strong
Merge bitcoin/bitcoin#36339: wallet: avoid int overflow in listtransactions

9cff82fd5b15bc2aa2c7778b61212876433a8219 wallet: avoid int overflow in listtransactions (Kanan)

Pull request description:

`listtransactions` adds `count` and `skip` as `int`. Each one is checked to be non-negative, but their sum can still go past INT_MAX:

```
bitcoin-cli -regtest listtransactions "*" 2147483647 1
```

On master this crashes the node. The overflowed sum is negative, so the loop stops after the first entry. The clamp after the loop overflows the same way and doesn't fix `nCount`, so `push_backV` gets an iterator range about 2^31 elements before `rend()`. UBSan reports `signed integer overflow: 1 + 2147483647` at transactions.cpp:584, and ASan then reports a BUS error in `UniValue::push_backV`.

This parses `count` and `skip` as `uint32_t` through `self.Arg` (which also handles the defaults and rejects negative values, so the manual checks go away) and adds them up in 64 bits, where the sum can't overflow. The functional test calls `listtransactions` with count + skip above INT_MAX and up to UINT32_MAX and checks the results match a normal-sized request. It times out on master (the node crashes) and passes with the fix. I also ran it on an ASan/UBSan build.

`listrawtransactions` counts differently and isn't affected.

ACKs for top commit:
maflcko:
lgtm ACK 9cff82fd5b15bc2aa2c7778b61212876433a8219
sedited:
ACK 9cff82fd5b15bc2aa2c7778b61212876433a8219

Tree-SHA512: 0068951efb724cf5551238de1c6b5d254b66594f9fe8878cf5bb49026e1624a8db6dc87eee23dfed38fc7620cef2933817e82ceb7f8072f8f89911f50af2e607
✓ 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 patch fixes a bug in Bitcoin Core's `listtransactions` RPC command. When a user asked for a very large number of transactions plus a large skip value, the wallet code added two integers together and overflowed, producing a negative number. That negative number was then used as a memory range, causing the node to crash. The fix reads the values as unsigned 32-bit integers and adds them in 64-bit arithmetic so the sum cannot overflow, and removes the now-redundant manual negative checks.

Recommended action

Apply the patch. Ensure RPC wallet endpoints consistently use unsigned or widened arithmetic for user-supplied counts and offsets, and consider adding regression tests for other pagination-style RPCs.

Security signals we found

01

signed integer overflow in RPC input handling

02

out-of-bounds iterator range leading to memory access violation

03

node crash (denial of service) from authenticated RPC call

04

ASan/UBSan-reported undefined behavior confirmed by reporter

05

missing input bounds clamping before arithmetic

Risk score

Why this scored 74/100

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