fix(swift-example-app): prevent UInt64.max overflow crash in TransferCreditsView amount parsing#3909
Conversation
…CreditsView amount parsing `parsedCredits` guarded the scaled credit amount with `credits <= Double(UInt64.max)`. `Double(UInt64.max)` isn't exactly representable and rounds up to 2^64, so the `<=` bound admitted 2^64 and the subsequent `UInt64(credits)` cast trapped. Because `parsedCredits` recomputes on every keystroke (before submit-time re-validation), typing a DASH amount that scales to ~2^64 credits (~1.844e8 DASH) crashed the Transfer Credits sheet instead of producing a friendly disabled-button state. Switched the bound to a strict `<` so 2^64 is rejected and the cast stays in range. Mirrors the same fix applied to WithdrawCreditsView in #3907. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIn ChangesUInt64 Overflow Boundary Fix
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
✅ Review complete (commit f47ca01) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
One-line <= → < fix in TransferCreditsView.parsedCredits correctly addresses the UInt64.max overflow trap caused by Double(UInt64.max) rounding to 2^64. Change is well-commented, narrowly scoped to the SwiftExampleApp, and surrounding guards already handle NaN/infinity/negative/sub-1 cases. Both agents found no in-scope defects.
Issue being fixed or feature implemented
TransferCreditsView.parsedCreditshad a crash-class bug identical to the one fixed inWithdrawCreditsView(#3907).It guarded the scaled credit amount with:
Double(UInt64.max)is not exactly representable and rounds up to 2^64, so the<=guard admitted a value (2^64) one aboveUInt64's representable range, andUInt64(credits)then trapped. BecauseparsedCreditsrecomputes on every keystroke (before any submit-time re-validation), a user typing a DASH amount that scales to ~2^64 credits (input around 1.844e8 DASH) crashed the Transfer Credits sheet on input instead of producing a friendly disabled-button state.What was done?
Changed the upper bound to a strict
<so 2^64 is rejected and theUInt64(credits)cast stays in range, with a comment explaining why. This mirrors the exact fix applied toWithdrawCreditsViewin #3907.How Has This Been Tested?
Built the app for the iOS simulator from
packages/swift-sdk:→ BUILD SUCCEEDED.
Breaking Changes
None.
Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
Summary by CodeRabbit