Skip to content

Commit 88d138b

Browse files
authored
Merge 6acc154 into 72a8746
2 parents 72a8746 + 6acc154 commit 88d138b

File tree

3 files changed

+252
-29
lines changed

3 files changed

+252
-29
lines changed

Sentry.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
6304360B1EC0595B00C4D3FA /* SentryNSDataUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 630436091EC0595B00C4D3FA /* SentryNSDataUtils.m */; };
155155
630436101EC0600A00C4D3FA /* SentrySerializable.h in Headers */ = {isa = PBXBuildFile; fileRef = 6304360F1EC0600A00C4D3FA /* SentrySerializable.h */; settings = {ATTRIBUTES = (Public, ); }; };
156156
630436161EC0AD3100C4D3FA /* SentryNSDataCompressionTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 630436151EC0AD3100C4D3FA /* SentryNSDataCompressionTests.m */; };
157-
630C01941EC3402C00C52CEF /* SentryKSCrashReportConverterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 630C01931EC3402C00C52CEF /* SentryKSCrashReportConverterTests.m */; };
157+
630C01941EC3402C00C52CEF /* SentryCrashReportConverterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 630C01931EC3402C00C52CEF /* SentryCrashReportConverterTests.m */; };
158158
630C01961EC341D600C52CEF /* Resources in Resources */ = {isa = PBXBuildFile; fileRef = 630C01951EC341D600C52CEF /* Resources */; };
159159
631501BB1EE6F30B00512C5B /* SentrySwizzleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 631501BA1EE6F30B00512C5B /* SentrySwizzleTests.m */; };
160160
631E6D331EBC679C00712345 /* SentryQueueableRequestManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 631E6D311EBC679C00712345 /* SentryQueueableRequestManager.h */; };
@@ -1395,7 +1395,7 @@
13951395
6304360D1EC05CEF00C4D3FA /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/lib/libz.tbd; sourceTree = DEVELOPER_DIR; };
13961396
6304360F1EC0600A00C4D3FA /* SentrySerializable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentrySerializable.h; path = Public/SentrySerializable.h; sourceTree = "<group>"; };
13971397
630436151EC0AD3100C4D3FA /* SentryNSDataCompressionTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentryNSDataCompressionTests.m; sourceTree = "<group>"; };
1398-
630C01931EC3402C00C52CEF /* SentryKSCrashReportConverterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentryKSCrashReportConverterTests.m; sourceTree = "<group>"; };
1398+
630C01931EC3402C00C52CEF /* SentryCrashReportConverterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentryCrashReportConverterTests.m; sourceTree = "<group>"; };
13991399
630C01951EC341D600C52CEF /* Resources */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Resources; sourceTree = "<group>"; };
14001400
631501BA1EE6F30B00512C5B /* SentrySwizzleTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SentrySwizzleTests.m; sourceTree = "<group>"; };
14011401
631E6D311EBC679C00712345 /* SentryQueueableRequestManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SentryQueueableRequestManager.h; path = include/SentryQueueableRequestManager.h; sourceTree = "<group>"; };
@@ -2995,7 +2995,7 @@
29952995
8431D4572BE175A1009EAEC1 /* SentryContinuousProfiler+Test.h */,
29962996
639889D21EDF06C100EA7442 /* SentryTests-Bridging-Header.h */,
29972997
63B819131EC352A7002FDF4C /* SentryInterfacesTests.m */,
2998-
630C01931EC3402C00C52CEF /* SentryKSCrashReportConverterTests.m */,
2998+
630C01931EC3402C00C52CEF /* SentryCrashReportConverterTests.m */,
29992999
630436151EC0AD3100C4D3FA /* SentryNSDataCompressionTests.m */,
30003000
63EED6C22237989300E02400 /* SentryOptionsTest.m */,
30013001
7B569DFF2590EEF600B653FC /* SentryScope+Equality.m */,
@@ -6165,7 +6165,7 @@
61656165
7BBD18A2244EE2FD00427C76 /* TestResponseFactory.swift in Sources */,
61666166
628B89022D841D7F004B6F2A /* SentryDateUtilsTests.swift in Sources */,
61676167
D808FB8B281BCE96009A2A33 /* TestSentrySwizzleWrapper.swift in Sources */,
6168-
630C01941EC3402C00C52CEF /* SentryKSCrashReportConverterTests.m in Sources */,
6168+
630C01941EC3402C00C52CEF /* SentryCrashReportConverterTests.m in Sources */,
61696169
7B59398424AB481B0003AAD2 /* NotificationCenterTestCase.swift in Sources */,
61706170
7B0A542E2521C62400A71716 /* SentryFrameRemoverTests.swift in Sources */,
61716171
7BE912B12721C76000E49E62 /* SentryPerformanceTrackingIntegrationTests.swift in Sources */,

Sources/Sentry/SentryCrashReportConverter.m

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)