Commit d1eab6c
committed
Merge #7236: fix: resolve signed integer overflow UB in CoinJoin priority and timeout
e8ec63a test: add regression tests for CoinJoin UB fixes (PastaClaw)
817234f fix: resolve signed integer overflow UB in CoinJoin priority and timeout (PastaClaw)
Pull request description:
## Summary
Fix two signed integer overflow UB issues in CoinJoin code, found during fuzz testing.
### `CalculateAmountPriority` (common.h)
The return type is `int` but the computation `-(nInputAmount / COIN)` operates on
`int64_t` values. When `nInputAmount` is extremely large (e.g. near `MAX_MONEY`),
the result exceeds `INT_MAX` and the implicit narrowing to `int` is undefined
behavior under UBSan.
**Fix:** Clamp the `int64_t` result to `[INT_MIN, INT_MAX]` before returning.
This preserves the existing sort ordering for all realistic inputs while making
extreme values well-defined.
### `IsTimeOutOfBounds` (coinjoin.cpp)
The expression `current_time - nTime` overflows when the two `int64_t` values
differ by more than `INT64_MAX` (e.g. one large positive, one large negative).
**Fix:** Compute the absolute difference using unsigned arithmetic, which is
well-defined for all inputs.
## Validation
- Both functions are non-consensus (CoinJoin sort priority and queue timeout only)
- Neither overflow is exploitable — CoinJoin queue entries require valid MN signatures,
and the priority function only affects local sort order
- The fixes preserve identical behavior for all realistic inputs
- Found via UBSan-instrumented fuzz testing on the `ci/fuzz-regression` branch
ACKs for top commit:
PastaPastaPasta:
utACK e8ec63a
UdjinM6:
utACK e8ec63a
PastaPastaPasta:
utACK e8ec63a
Tree-SHA512: 92f2f2abe0b3dd837c45cdb8d25e65454083fac0be268252f93b477c4355b91095b45393efc05561cbdf6e46e9d68b4c9c60d2255c6ac7a679905e9e3f0c55fb3 files changed
Lines changed: 51 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
13 | 18 | | |
14 | 19 | | |
15 | 20 | | |
| |||
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
99 | 148 | | |
0 commit comments