Skip to content

Commit e537c90

Browse files
authored
fix: Fix crash when last replay info is missing some keys (#6577)
* fix: Fix crash when last replay info is missing keys * Update changelog
1 parent 41834f1 commit e537c90

File tree

4 files changed

+28
-6
lines changed

4 files changed

+28
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Fix crash when last replay info is missing some keys [#6577]
8+
39
## 8.57.0
410

511
> [!Warning]

Sources/Sentry/SentrySessionReplayIntegration.m

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# import "SentryEvent+Private.h"
1111
# import "SentryFileManager.h"
1212
# import "SentryHub+Private.h"
13+
# import "SentryInternalDefines.h"
1314
# import "SentryLogC.h"
1415
# import "SentryOptions.h"
1516
# import "SentryRateLimits.h"
@@ -215,10 +216,25 @@ - (void)resumePreviousSessionReplay:(SentryEvent *)event
215216
return;
216217
}
217218

218-
SentryId *replayId = jsonObject[@"replayId"]
219-
? [[SentryId alloc] initWithUUIDString:jsonObject[@"replayId"]]
220-
: [[SentryId alloc] init];
221-
NSURL *lastReplayURL = [dir URLByAppendingPathComponent:jsonObject[@"path"]];
219+
SentryId *replayId;
220+
if (jsonObject[@"replayId"] && [jsonObject[@"replayId"] isKindOfClass:NSString.class]) {
221+
replayId = [[SentryId alloc]
222+
initWithUUIDString:SENTRY_UNWRAP_NULLABLE(NSString, jsonObject[@"replayId"])];
223+
} else {
224+
replayId = [[SentryId alloc] init];
225+
}
226+
if (!jsonObject[@"path"] || ![jsonObject[@"path"] isKindOfClass:NSString.class]) {
227+
SENTRY_LOG_ERROR(@"[Session Replay] Failed to read path from last replay");
228+
return;
229+
}
230+
NSURL *_Nullable nullableUrl =
231+
[dir URLByAppendingPathComponent:SENTRY_UNWRAP_NULLABLE(NSString, jsonObject[@"path"])];
232+
if (!nullableUrl) {
233+
SENTRY_LOG_ERROR(
234+
@"[Session Replay] Failed to create URL with path: %@", jsonObject[@"path"]);
235+
return;
236+
}
237+
NSURL *_Nonnull lastReplayURL = SENTRY_UNWRAP_NULLABLE(NSURL, nullableUrl);
222238

223239
SentryCrashReplay crashInfo = { 0 };
224240
bool hasCrashInfo = sentrySessionReplaySync_readInfo(&crashInfo,

scripts/.clang-format-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
21.1.3
1+
21.1.4

scripts/.swiftlint-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.61.0
1+
0.62.2

0 commit comments

Comments
 (0)