@@ -51,7 +51,7 @@ - (instancetype)initWithReport:(NSDictionary *)report inAppLogic:(SentryInAppLog
5151 // here. For more details please check out SentryCrashScopeObserver.
5252 NSMutableDictionary *userContextMerged =
5353 [[NSMutableDictionary alloc ] initWithDictionary: userContextUnMerged];
54- [userContextMerged addEntriesFromDictionary: report[@" sentry_sdk_scope" ]];
54+ [userContextMerged addEntriesFromDictionary: report[@" sentry_sdk_scope" ] ?: @{} ];
5555 [userContextMerged removeObjectForKey: @" sentry_sdk_scope" ];
5656 self.userContext = userContextMerged;
5757
@@ -108,8 +108,9 @@ - (SentryEvent *_Nullable)convertReportToEvent
108108 if ([self .report[@" report" ][@" timestamp" ] isKindOfClass: NSNumber .class]) {
109109 event.timestamp = [NSDate
110110 dateWithTimeIntervalSince1970: [self .report[@" report" ][@" timestamp" ] integerValue ]];
111- } else {
112- event.timestamp = sentry_fromIso8601String (self.report [@" report" ][@" timestamp" ]);
111+ } else if ([self .report[@" report" ][@" timestamp" ] isKindOfClass: NSString .class]) {
112+ event.timestamp = sentry_fromIso8601String (
113+ SENTRY_UNWRAP_NULLABLE (NSString , self.report [@" report" ][@" timestamp" ]));
113114 }
114115 event.threads = [self convertThreads ];
115116 event.debugMeta = [self debugMetaForThreads: event.threads];
@@ -119,7 +120,7 @@ - (SentryEvent *_Nullable)convertReportToEvent
119120 event.environment = self.userContext [@" environment" ];
120121
121122 NSMutableDictionary *mutableContext =
122- [[NSMutableDictionary alloc ] initWithDictionary: self .userContext[@" context" ]];
123+ [[NSMutableDictionary alloc ] initWithDictionary: self .userContext[@" context" ] ?: @{} ];
123124 if (self.userContext [@" traceContext" ]) {
124125 mutableContext[@" trace" ] = self.userContext [@" traceContext" ];
125126 }
@@ -186,13 +187,19 @@ - (SentryUser *_Nullable)convertUser
186187 if (nil != self.userContext [@" breadcrumbs" ]) {
187188 NSArray *storedBreadcrumbs = self.userContext [@" breadcrumbs" ];
188189 for (NSDictionary *storedCrumb in storedBreadcrumbs) {
190+ if (!storedCrumb[@" category" ]) {
191+ continue ;
192+ }
189193 SentryBreadcrumb *crumb = [[SentryBreadcrumb alloc ]
190194 initWithLevel: [self sentryLevelFromString: storedCrumb[@" level" ]]
191- category: storedCrumb[@" category" ]];
195+ category: SENTRY_UNWRAP_NULLABLE ( NSString , storedCrumb[@" category" ]) ];
192196 crumb.message = storedCrumb[@" message" ];
193197 crumb.type = storedCrumb[@" type" ];
194198 crumb.origin = storedCrumb[@" origin" ];
195- crumb.timestamp = sentry_fromIso8601String (storedCrumb[@" timestamp" ]);
199+ if ([storedCrumb[@" timestamp" ] isKindOfClass: NSString .class]) {
200+ crumb.timestamp = sentry_fromIso8601String (
201+ SENTRY_UNWRAP_NULLABLE (NSString , storedCrumb[@" timestamp" ]));
202+ }
196203 crumb.data = storedCrumb[@" data" ];
197204 [breadcrumbs addObject: crumb];
198205 }
@@ -255,7 +262,12 @@ - (SentryThread *_Nullable)threadAtIndex:(NSInteger)threadIndex
255262 }
256263 NSDictionary *threadDictionary = self.threads [threadIndex];
257264
258- SentryThread *thread = [[SentryThread alloc ] initWithThreadId: threadDictionary[@" index" ]];
265+ if (![threadDictionary[@" index" ] isKindOfClass: [NSNumber class ]]) {
266+ SENTRY_LOG_ERROR (@" Thread index is not a number: %@ " , threadDictionary[@" index" ]);
267+ return nil ;
268+ }
269+ NSNumber *threadId = SENTRY_UNWRAP_NULLABLE (NSNumber , threadDictionary[@" index" ]);
270+ SentryThread *thread = [[SentryThread alloc ] initWithThreadId: threadId];
259271 // We only want to add the stacktrace if this thread hasn't crashed
260272 thread.stacktrace = [self stackTraceForThreadIndex: threadIndex];
261273 if (thread.stacktrace .frames .count == 0 ) {
@@ -266,7 +278,7 @@ - (SentryThread *_Nullable)threadAtIndex:(NSInteger)threadIndex
266278 thread.current = threadDictionary[@" current_thread" ];
267279 thread.name = threadDictionary[@" name" ];
268280 // We don't have access to the MachineContextWrapper but we know first thread is always the main
269- thread.isMain = [NSNumber numberWithBool: thread. threadId.intValue == 0 ];
281+ thread.isMain = [NSNumber numberWithBool: threadId.intValue == 0 ];
270282 if (nil == thread.name ) {
271283 thread.name = threadDictionary[@" dispatch_queue" ];
272284 }
@@ -357,9 +369,11 @@ - (SentryDebugMeta *)debugMetaFromBinaryImageDictionary:(NSDictionary *)sourceIm
357369
358370 for (SentryThread *thread in threads) {
359371 for (SentryFrame *frame in thread.stacktrace .frames ) {
360- if (frame.imageAddress && ![imageNames containsObject: frame.imageAddress]) {
361- [imageNames addObject: frame.imageAddress];
372+ NSString *_Nullable nullableImageAddress = frame.imageAddress ;
373+ if (nullableImageAddress == nil ) {
374+ continue ;
362375 }
376+ [imageNames addObject: SENTRY_UNWRAP_NULLABLE (NSString , nullableImageAddress)];
363377 }
364378 }
365379
@@ -399,19 +413,20 @@ - (SentryDebugMeta *)debugMetaFromBinaryImageDictionary:(NSDictionary *)sourceIm
399413 self .exceptionContext[@" mach" ][@" exception" ],
400414 self .exceptionContext[@" mach" ][@" code" ],
401415 self .exceptionContext[@" mach" ][@" subcode" ]]
402- type: self .exceptionContext[@" mach" ][@" exception_name" ]];
416+ type: self .exceptionContext[@" mach" ][@" exception_name" ] ?: @" Mach Exception " ];
403417 } else if ([exceptionType isEqualToString: @" signal" ]) {
404- exception =
405- [[SentryException alloc ] initWithValue: [NSString stringWithFormat: @" Signal %@ , Code %@ " ,
406- self .exceptionContext[@" signal" ][@" signal" ],
407- self .exceptionContext[@" signal" ][@" code" ]]
408- type: self .exceptionContext[@" signal" ][@" name" ]];
418+ exception = [[SentryException alloc ]
419+ initWithValue: [NSString stringWithFormat: @" Signal %@ , Code %@ " ,
420+ self .exceptionContext[@" signal" ][@" signal" ],
421+ self .exceptionContext[@" signal" ][@" code" ]]
422+ type: self .exceptionContext[@" signal" ][@" name" ] ?: @" Signal Exception " ];
409423 } else if ([exceptionType isEqualToString: @" user" ]) {
410424 NSString *exceptionReason =
411425 [NSString stringWithFormat: @" %@ " , self .exceptionContext[@" reason" ]];
412- exception = [[SentryException alloc ]
413- initWithValue: exceptionReason
414- type: self .exceptionContext[@" user_reported" ][@" name" ]];
426+ exception =
427+ [[SentryException alloc ] initWithValue: exceptionReason
428+ type: self .exceptionContext[@" user_reported" ][@" name" ]
429+ ?: @" User Reported Exception" ];
415430
416431 NSRange match = [exceptionReason rangeOfString: @" :" ];
417432 if (match.location != NSNotFound ) {
@@ -453,8 +468,9 @@ - (SentryException *)parseNSException
453468 reason = self.exceptionContext [@" reason" ];
454469 }
455470
456- return [[SentryException alloc ] initWithValue: [NSString stringWithFormat: @" %@ " , reason]
457- type: self .exceptionContext[@" nsexception" ][@" name" ]];
471+ return [[SentryException alloc ]
472+ initWithValue: [NSString stringWithFormat: @" %@ " , reason]
473+ type: self .exceptionContext[@" nsexception" ][@" name" ] ?: @" NSException" ];
458474}
459475
460476- (void )enhanceValueFromNotableAddresses : (SentryException *)exception
@@ -464,15 +480,15 @@ - (void)enhanceValueFromNotableAddresses:(SentryException *)exception
464480 return ;
465481 }
466482 NSDictionary *crashedThread = self.threads [self .crashedThreadIndex];
467- NSDictionary *notableAddresses = crashedThread[@" notable_addresses" ];
483+ NSDictionary *_Nullable notableAddresses = crashedThread[@" notable_addresses" ];
468484 NSMutableOrderedSet *reasons = [[NSMutableOrderedSet alloc ] init ];
469485 if (nil != notableAddresses) {
470486 for (id key in notableAddresses) {
471487 NSDictionary *content = notableAddresses[key];
472488 if ([content[@" type" ] isEqualToString: @" string" ] && nil != content[@" value" ]) {
473489 // if there are less than 3 slashes it shouldn't be a filepath
474490 if ([[content[@" value" ] componentsSeparatedByString: @" /" ] count ] < 3 ) {
475- [reasons addObject: content[@" value" ]];
491+ [reasons addObject: SENTRY_UNWRAP_NULLABLE ( NSString , content[@" value" ]) ];
476492 }
477493 }
478494 }
@@ -497,11 +513,13 @@ - (void)enhanceValueFromCrashInfoMessage:(SentryException *)exception
497513
498514 for (NSDictionary *binaryImage in libSwiftCoreBinaryImages) {
499515 if (binaryImage[@" crash_info_message" ] != nil ) {
500- [crashInfoMessages addObject: binaryImage[@" crash_info_message" ]];
516+ [crashInfoMessages
517+ addObject: SENTRY_UNWRAP_NULLABLE (NSString , binaryImage[@" crash_info_message" ])];
501518 }
502519
503520 if (binaryImage[@" crash_info_message2" ] != nil ) {
504- [crashInfoMessages addObject: binaryImage[@" crash_info_message2" ]];
521+ [crashInfoMessages
522+ addObject: SENTRY_UNWRAP_NULLABLE (NSString , binaryImage[@" crash_info_message2" ])];
505523 }
506524 }
507525
0 commit comments