From f47ca01a053c869f85b85b87d784d9b748db92bf Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Mon, 15 Jun 2026 22:27:01 +0100 Subject: [PATCH] fix(swift-example-app): prevent UInt64.max overflow crash in TransferCreditsView 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) --- .../SwiftExampleApp/Views/TransferCreditsView.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TransferCreditsView.swift b/packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TransferCreditsView.swift index 898cdaa1f26..4c4b5ffa666 100644 --- a/packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TransferCreditsView.swift +++ b/packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TransferCreditsView.swift @@ -224,7 +224,11 @@ struct TransferCreditsView: View { return nil } let credits = (dash * Double(Self.creditsPerDash)).rounded() - guard credits >= 1, credits <= Double(UInt64.max) else { return nil } + // Strict `<`: `Double(UInt64.max)` isn't exactly representable and + // rounds up to 2^64, so a `<=` bound would admit 2^64 and trap on + // the `UInt64(credits)` cast (this recomputes on every keystroke, + // before submit-time re-validation). `<` keeps it in range. + guard credits >= 1, credits < Double(UInt64.max) else { return nil } return UInt64(credits) }