Skip to content

Commit

Permalink
[to delete] Try to repro BackgroundTask crash
Browse files Browse the repository at this point in the history
- Reports of OSBackgroundTaskHandlerImpl.beginBackgroundTask crashing with trace
- objc_msgSend + 8
- [__NSDictionaryM setObject:forKeyedSubscript:] + 484

That was reproduced by passing in a nil taskIdentifier, but how could that happen?
  • Loading branch information
nan-li committed Feb 22, 2024
1 parent 09272b4 commit b4dc632
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions iOS_SDK/OneSignalSDK/Source/OSBackgroundTaskHandlerImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,31 @@ - (void)beginBackgroundTask:(NSString * _Nonnull)taskIdentifier {
[self endBackgroundTask:taskIdentifier];
}];
tasks[taskIdentifier] = [NSNumber numberWithUnsignedLong:uiIdentifier];
[self tryToReproCrash:taskIdentifier];
}

- (void)tryToReproCrash:(NSString*)taskIdentifier {
// 1. This is fine, doesnt crash
tasks[taskIdentifier] = [NSNumber numberWithUnsignedLong:nil];

// 2. This is apparently fine too, doesnt crash
tasks[taskIdentifier] = nil;

// 3. This is fine too
tasks = nil;
tasks[taskIdentifier] = [NSNumber numberWithUnsignedLong:5];

// 4. This crashes with the stacktrace

tasks = [NSMutableDictionary new];
taskIdentifier = nil;
tasks[taskIdentifier] = [NSNumber numberWithUnsignedLong:5];
// objc_msgSend$callStackReturnAddresses
// 0x00000001a410a048 in -[__NSDictionaryM setObject:forKeyedSubscript:] ()
// 0x0000000101b430b8 in -[OSBackgroundTaskHandlerImpl beginBackgroundTask:] at OSBackgroundTaskHandlerImpl.m:66

NSLog(@"Tasks: %@", tasks);
}
- (void)endBackgroundTask:(NSString * _Nonnull)taskIdentifier {
UIBackgroundTaskIdentifier uiIdentifier = [[tasks objectForKey:taskIdentifier] unsignedLongValue];
[OneSignalLog onesignalLog:ONE_S_LL_DEBUG
Expand Down

0 comments on commit b4dc632

Please sign in to comment.