Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash introduced with uint64 support #2664

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

### Fixes

- Support uint64 in crash reports (#2631, #2642)
- Support uint64 in crash reports (#2631, #2642, #2663)
- Always fetch view hierarchy on the main thread (#2629)
- Carthage Xcode 14 compatibility issue (#2636)
- Crash in CppException Monitor (#2639)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ onIntegerElement(const char *const name, const int64_t value, void *const userDa
return onFloatingPointElement(name, value, userData);
}

static int
onUIntegerElement(
__unused const char *const name, __unused const uint64_t value, __unused void *const userData)
{
return SentryCrashJSON_OK;
}

static int
onNullElement(__unused const char *const name, __unused void *const userData)
{
Expand Down Expand Up @@ -234,6 +241,7 @@ loadState(const char *const path)
callbacks.onEndData = onEndData;
callbacks.onFloatingPointElement = onFloatingPointElement;
callbacks.onIntegerElement = onIntegerElement;
callbacks.onUIntegerElement = onUIntegerElement;
callbacks.onNullElement = onNullElement;
callbacks.onStringElement = onStringElement;

Expand Down
8 changes: 8 additions & 0 deletions Sources/SentryCrash/Recording/SentryCrashReportFixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ onIntegerElement(const char *const name, const int64_t value, void *const userDa
return result;
}

static int
onUIntegerElement(const char *const name, const uint64_t value, void *const userData)
{
FixupContext *context = (FixupContext *)userData;
return sentrycrashjson_addUIntegerElement(context->encodeContext, name, value);
}

static int
onNullElement(const char *const name, void *const userData)
{
Expand Down Expand Up @@ -230,6 +237,7 @@ sentrycrashcrf_fixupCrashReport(const char *crashReport)
.onEndData = onEndData,
.onFloatingPointElement = onFloatingPointElement,
.onIntegerElement = onIntegerElement,
.onUIntegerElement = onUIntegerElement,
.onNullElement = onNullElement,
.onStringElement = onStringElement,
};
Expand Down
8 changes: 8 additions & 0 deletions Tests/Resources/CrashState_unsupported_fields.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"version": 9223372036854775808,
"crashedLastLaunch": "false",
"activeDurationSinceLastCrash": null,
"backgroundDurationSinceLastCrash": {
"not": "supported"
},
}
4 changes: 2 additions & 2 deletions Tests/Resources/processed.json
Original file line number Diff line number Diff line change
Expand Up @@ -2544,8 +2544,8 @@
"cs": 11,
"ds": 35,
"es": 35,
"fs": 35,
"gs": 15
"fs": 9223372036854775807,
"gs": 9223372036854775808
}
},
"index": 5,
Expand Down
4 changes: 2 additions & 2 deletions Tests/Resources/raw.json
Original file line number Diff line number Diff line change
Expand Up @@ -2544,8 +2544,8 @@
"cs": 11,
"ds": 35,
"es": 35,
"fs": 35,
"gs": 15
"fs": 9223372036854775807,
"gs": 9223372036854775808
}
},
"index": 5,
Expand Down
55 changes: 37 additions & 18 deletions Tests/SentryTests/SentryCrash/SentryCrashMonitor_AppState_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,10 @@ - (void)testInitWithWrongCrashState
[jsonData writeToFile:stateFile atomically:true];

[self initializeCrashState];
SentryCrash_AppState context = *sentrycrashstate_currentState();

XCTAssertTrue(context.applicationIsInForeground);
XCTAssertFalse(context.applicationIsActive);

XCTAssertEqual(context.activeDurationSinceLastCrash, 0.0);
XCTAssertEqual(context.backgroundDurationSinceLastCrash, 0.0);
XCTAssertEqual(context.launchesSinceLastCrash, 1);
XCTAssertEqual(context.sessionsSinceLastCrash, 1);

XCTAssertEqual(context.activeDurationSinceLaunch, 0.0);
XCTAssertEqual(context.backgroundDurationSinceLaunch, 0.0);
XCTAssertEqual(context.sessionsSinceLaunch, 1);

XCTAssertFalse(context.crashedThisLaunch);
XCTAssertFalse(context.crashedLastLaunch);
XCTAssertEqual(context.durationFromCrashStateInitToLastCrash, 0.0);
[self assertDefaultCrashState];

[self initializeCrashState];
context = *sentrycrashstate_currentState();
SentryCrash_AppState context = *sentrycrashstate_currentState();
XCTAssertEqual(context.launchesSinceLastCrash, 2);
XCTAssertEqual(context.sessionsSinceLastCrash, 2);

Expand All @@ -186,6 +170,20 @@ - (void)testInitWithWrongCrashState
XCTAssertEqual(context.sessionsSinceLastCrash, 1);
}

- (void)testInitWithUnsupportedFields
{
NSString *stateFile = [self.tempPath stringByAppendingPathComponent:@"state.json"];
NSString *jsonPath = [[NSBundle bundleForClass:self.class]
pathForResource:@"Resources/CrashState_unsupported_fields"
ofType:@"json"];
NSData *jsonData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:jsonPath]];
[jsonData writeToFile:stateFile atomically:true];

[self initializeCrashState];

[self assertDefaultCrashState];
}

- (void)testInitWithCrashStateLegacy
{
NSString *stateFile = [self.tempPath stringByAppendingPathComponent:@"state.json"];
Expand Down Expand Up @@ -714,4 +712,25 @@ - (void)testActDeactBGFGCrash
XCTAssertLessThan(context.durationFromCrashStateInitToLastCrash, 1.0);
}

- (void)assertDefaultCrashState
{
SentryCrash_AppState context = *sentrycrashstate_currentState();

XCTAssertTrue(context.applicationIsInForeground);
XCTAssertFalse(context.applicationIsActive);

XCTAssertEqual(context.activeDurationSinceLastCrash, 0.0);
XCTAssertEqual(context.backgroundDurationSinceLastCrash, 0.0);
XCTAssertEqual(context.launchesSinceLastCrash, 1);
XCTAssertEqual(context.sessionsSinceLastCrash, 1);

XCTAssertEqual(context.activeDurationSinceLaunch, 0.0);
XCTAssertEqual(context.backgroundDurationSinceLaunch, 0.0);
XCTAssertEqual(context.sessionsSinceLaunch, 1);

XCTAssertFalse(context.crashedThisLaunch);
XCTAssertFalse(context.crashedLastLaunch);
XCTAssertEqual(context.durationFromCrashStateInitToLastCrash, 0.0);
}

@end