From e6f0640e995cdd8335625161028737010f315c5f Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Thu, 20 Mar 2025 17:24:59 +1100 Subject: [PATCH 1/3] Attempt to prevent an odd NaN crash --- Session/Meta/AppDelegate.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Session/Meta/AppDelegate.swift b/Session/Meta/AppDelegate.swift index 726e5bcd6..d9e2daf8a 100644 --- a/Session/Meta/AppDelegate.swift +++ b/Session/Meta/AppDelegate.swift @@ -322,9 +322,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD /// /// Additionally we want to ensure that our timeout timer has enough time to run so make sure we have at least `5 seconds` /// of background execution (if we don't then the process could incorrectly run longer than it should) + let remainingTime: TimeInterval = application.backgroundTimeRemaining + guard - application.backgroundTimeRemaining < TimeInterval.greatestFiniteMagnitude && - application.backgroundTimeRemaining > 5 + remainingTime != TimeInterval.nan && + remainingTime < TimeInterval.greatestFiniteMagnitude && + remainingTime > 5 else { return completionHandler(.failed) } Log.appResumedExecution() @@ -342,7 +345,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD /// /// **Note:** We **MUST** capture both `poller` and `cancellable` strongly in the event handler to ensure neither /// go out of scope until we want them to (we essentually want a retain cycle in this case) - let durationRemainingMs: Int = max(1, Int((application.backgroundTimeRemaining - 5) * 1000)) + let durationRemainingMs: Int = max(1, Int((remainingTime - 5) * 1000)) let timer: DispatchSourceTimer = DispatchSource.makeTimerSource(queue: queue) timer.schedule(deadline: .now() + .milliseconds(durationRemainingMs)) timer.setEventHandler { [poller, dependencies] in From 95f4150c9606aeafc09da049fa4f6e76c3644acb Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Thu, 20 Mar 2025 17:28:30 +1100 Subject: [PATCH 2/3] Use a guard to prevent an implicit unwrap --- .../LibSession+SessionMessagingKit.swift | 11 ++--------- SessionMessagingKit/LibSession/Types/Config.swift | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/SessionMessagingKit/LibSession/LibSession+SessionMessagingKit.swift b/SessionMessagingKit/LibSession/LibSession+SessionMessagingKit.swift index 8f82aa7dd..e28083e94 100644 --- a/SessionMessagingKit/LibSession/LibSession+SessionMessagingKit.swift +++ b/SessionMessagingKit/LibSession/LibSession+SessionMessagingKit.swift @@ -608,15 +608,8 @@ public extension LibSession { // Only generate the push data if we need to do a push guard config.needsPush else { return } - guard let data: PendingChanges.PushData = config.push(variant: info.variant) else { - throw LibSessionError( - config, - fallbackError: .unableToGeneratePushData, - logMessage: "Failed to generate push data for \(info.variant) config data, size: \(config.countDescription), error" - ) - } - - result.append(data: data) + // Try to generate the push data (will throw if there is an error) + try result.append(data: config.push(variant: info.variant)) } } diff --git a/SessionMessagingKit/LibSession/Types/Config.swift b/SessionMessagingKit/LibSession/Types/Config.swift index 2786adf11..b9ee340d9 100644 --- a/SessionMessagingKit/LibSession/Types/Config.swift +++ b/SessionMessagingKit/LibSession/Types/Config.swift @@ -124,12 +124,22 @@ public extension LibSession { // MARK: - Functions - func push(variant: ConfigDump.Variant) -> PendingChanges.PushData? { + func push(variant: ConfigDump.Variant) throws -> PendingChanges.PushData? { switch self { case .userProfile(let conf), .contacts(let conf), .convoInfoVolatile(let conf), .userGroups(let conf), .groupInfo(let conf), .groupMembers(let conf): - let cPushData: UnsafeMutablePointer = config_push(conf) + /// The `config_push` function implicitly unwraps it's value but can throw internally so call it in a guard + /// statement to prevent the implicit unwrap from causing a crash (ideally it would return a standard optional + /// so the compiler would warn us but it's not that straight forward when dealing with C) + guard let cPushData: UnsafeMutablePointer = config_push(conf) else { + throw LibSessionError( + self, + fallbackError: .unableToGeneratePushData, + logMessage: "Failed to generate push data for \(variant) config data, size: \(countDescription), error" + ) + } + let pushData: Data = Data( bytes: cPushData.pointee.config, count: cPushData.pointee.config_len From d6a2d6edd74d0557da6e6c012a356f465daa48ad Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Tue, 25 Mar 2025 18:24:31 +1100 Subject: [PATCH 3/3] Updated build and version numbers --- Session.xcodeproj/project.pbxproj | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 4759ec572..a23dffa00 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -7861,7 +7861,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; COMPILE_LIB_SESSION = ""; - CURRENT_PROJECT_VERSION = 561; + CURRENT_PROJECT_VERSION = 563; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -7900,7 +7900,7 @@ HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/include/**"; IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.1; + MARKETING_VERSION = 2.9.2; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = "-Werror=protocol"; OTHER_SWIFT_FLAGS = "-D DEBUG -Xfrontend -warn-long-expression-type-checking=100"; @@ -7939,7 +7939,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; COMPILE_LIB_SESSION = ""; - CURRENT_PROJECT_VERSION = 561; + CURRENT_PROJECT_VERSION = 563; ENABLE_BITCODE = NO; ENABLE_MODULE_VERIFIER = YES; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -7974,7 +7974,7 @@ HEADER_SEARCH_PATHS = "$(BUILT_PRODUCTS_DIR)/include/**"; IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.1; + MARKETING_VERSION = 2.9.2; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = ( "-DNS_BLOCK_ASSERTIONS=1", @@ -8483,7 +8483,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; COMPILE_LIB_SESSION = YES; - CURRENT_PROJECT_VERSION = 561; + CURRENT_PROJECT_VERSION = 563; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -8524,7 +8524,7 @@ ); IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.1; + MARKETING_VERSION = 2.9.2; ONLY_ACTIVE_ARCH = YES; OTHER_CFLAGS = ( "-fobjc-arc-exceptions", @@ -9151,7 +9151,7 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; COMPILE_LIB_SESSION = YES; - CURRENT_PROJECT_VERSION = 561; + CURRENT_PROJECT_VERSION = 563; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_NO_COMMON_BLOCKS = YES; @@ -9187,7 +9187,7 @@ ); IPHONEOS_DEPLOYMENT_TARGET = 15.6; LIB_SESSION_SOURCE_DIR = "${SRCROOT}/../LibSession-Util"; - MARKETING_VERSION = 2.9.1; + MARKETING_VERSION = 2.9.2; ONLY_ACTIVE_ARCH = NO; OTHER_CFLAGS = ( "-DNS_BLOCK_ASSERTIONS=1",