fix: resolve signed integer overflow UB in CoinJoin priority and timeout#7236
fix: resolve signed integer overflow UB in CoinJoin priority and timeout#7236thepastaclaw wants to merge 1 commit intodashpay:developfrom
Conversation
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
|
WalkthroughThe pull request contains two safety and optimization improvements to the coinjoin module. The first change simplifies timeout validation in Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/coinjoin/coinjoin.cpp`:
- Around line 57-61: Run clang-format on the indicated block (or the whole file)
to fix the whitespace/line-wrapping so the ternary expression and return
statement match project style; reformat the block containing current_time, nTime
and COINJOIN_QUEUE_TIMEOUT (the diff calculation and return) using your
project's clang-format config and commit the changes so the Clang Diff Format
Check passes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 82b1eff3-1f1e-4510-a19f-8c06e26a762b
📒 Files selected for processing (2)
src/coinjoin/coinjoin.cppsrc/coinjoin/common.h
| { | ||
| return current_time - nTime > COINJOIN_QUEUE_TIMEOUT || | ||
| nTime - current_time > COINJOIN_QUEUE_TIMEOUT; | ||
| const uint64_t diff = (current_time > nTime) | ||
| ? static_cast<uint64_t>(current_time) - static_cast<uint64_t>(nTime) | ||
| : static_cast<uint64_t>(nTime) - static_cast<uint64_t>(current_time); | ||
| return diff > static_cast<uint64_t>(COINJOIN_QUEUE_TIMEOUT); |
There was a problem hiding this comment.
Run clang-format on this block to unblock CI.
The pipeline reports formatting differences at Line 57 in this function. Please apply clang-format to this region/file so the Clang Diff Format Check passes.
🧰 Tools
🪛 GitHub Actions: Clang Diff Format Check
[error] 57-57: Clang format differences detected in this file. Please run clang-format to fix formatting issues as shown by the diff.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/coinjoin/coinjoin.cpp` around lines 57 - 61, Run clang-format on the
indicated block (or the whole file) to fix the whitespace/line-wrapping so the
ternary expression and return statement match project style; reformat the block
containing current_time, nTime and COINJOIN_QUEUE_TIMEOUT (the diff calculation
and return) using your project's clang-format config and commit the changes so
the Clang Diff Format Check passes.
CalculateAmountPriority in common.h could overflow when assigning a negated int64_t division result to an int return type with extreme CAmount values. Clamp the result to INT_MIN/INT_MAX before returning. IsTimeOutOfBounds in coinjoin.cpp could overflow on signed subtraction when current_time and nTime differ by more than INT64_MAX. Use unsigned arithmetic to compute the absolute difference safely. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4248612 to
dbfbbe6
Compare
Summary
Fix two signed integer overflow UB issues in CoinJoin code, found during fuzz testing.
CalculateAmountPriority(common.h)The return type is
intbut the computation-(nInputAmount / COIN)operates onint64_tvalues. WhennInputAmountis extremely large (e.g. nearMAX_MONEY),the result exceeds
INT_MAXand the implicit narrowing tointis undefinedbehavior under UBSan.
Fix: Clamp the
int64_tresult 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 - nTimeoverflows when the twoint64_tvaluesdiffer 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
and the priority function only affects local sort order
ci/fuzz-regressionbranch