Skip to content

Commit 817234f

Browse files
thepastaclawclaude
andcommitted
fix: resolve signed integer overflow UB in CoinJoin priority and timeout
CalculateAmountPriority in common.h could overflow when assigning a negated int64_t division result to an int return type with extreme CAmount values. Add a MoneyRange guard to return 0 for out-of-range inputs, as CoinJoin amounts are always within valid money range. IsTimeOutOfBounds in coinjoin.cpp could overflow on signed subtraction when current_time and nTime are extreme values. Add a guard rejecting negative timestamps (which are always invalid) so the original subtraction logic is safe for all remaining non-negative inputs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1d212a1 commit 817234f

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

src/coinjoin/coinjoin.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ bool CCoinJoinQueue::CheckSignature(const CBLSPublicKey& blsPubKey) const
5757

5858
bool CCoinJoinQueue::IsTimeOutOfBounds(int64_t current_time) const
5959
{
60+
if (current_time < 0 || nTime < 0) return true;
6061
return current_time - nTime > COINJOIN_QUEUE_TIMEOUT ||
6162
nTime - current_time > COINJOIN_QUEUE_TIMEOUT;
6263
}

src/coinjoin/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ constexpr bool IsCollateralAmount(CAmount nInputAmount)
118118

119119
constexpr int CalculateAmountPriority(CAmount nInputAmount)
120120
{
121+
if (nInputAmount < 0 || nInputAmount > MAX_MONEY) return 0;
121122
if (auto optDenom = util::find_if_opt(GetStandardDenominations(),
122123
[&nInputAmount](const auto& denom) { return nInputAmount == denom; })) {
123124
return (float)COIN / *optDenom * 10000;

0 commit comments

Comments
 (0)