Skip to content

Conversation

bitsandfoxes
Copy link
Contributor

@bitsandfoxes bitsandfoxes commented Sep 22, 2025

Superseds #2321

The Problem

We've received different crash events originating from the SDK when running on Apple platforms.

Date Formatting

The first crash we have is

EXC_BAD_ACCESS (SIGSEGV)
  Exception Type: EXC_BAD_ACCESS (SIGSEGV)
  Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000

  Application Specific Information:
  Crashed in icu::Calendar::clear()

  Thread 0 Crashed:
  0   libicucore.A.dylib                  0x1981de8c4 icu::Calendar::clear() + 164
  1   CoreFoundation                      0x18e59f1dc CFDateFormatterGetAbsoluteTimeFromString + 632
  2   CoreFoundation                      0x18e59e030 CFDateFormatterCreateDateFromString + 724
  3   Foundation                          0x18d1642a8 getObjectValue + 244
  4   Foundation                          0x18d165438 -[NSDateFormatter getObjectValue:forString:errorDescription:] + 192
  5   Foundation                          0x18d163ff0 -[NSDateFormatter dateFromString:] + 52
  6   Sentry.framework                    0x10cbb42b0 __SentryNativeBridgeAddBreadcrumb_block_invoke + 116
  7   Sentry.framework                    0x100969784 -[SentryHub configureScope:] + 52
  8   Sentry.framework                    0x100995224 +[SentrySDK configureScope:] + 56
  9   Sentry.framework                    0x10cbb41c8 SentryNativeBridgeAddBreadcrumb + 652
  10  Sentry.framework                    0x113bd2448 SentryCocoaBridgeProxy_AddBreadcrumb + 3366
  11  Sentry.framework                    0x113bbe034 NativeScopeObserver_AddBreadcrumbImpl + 1522
  12  Sentry.framework                    0x113af037c ScopeObserver_AddBreadcrumb + 828
  13  Sentry.framework                    0x113aefaac HubExtensions_AddBreadcrumb + 556
  14  Sentry.framework                    0x113bcfc9c UnityApplicationLoggingIntegration_OnLogMessageReceived + 29343

This hints at invalid date formatting with NSDateFormatter.dateFromString attempting to parse the timestamp using an invalid memory pointer, causing icu::Calendar::clear() to dereference NULL (x0: 0x0).

Breadcrumb Serialization Issue

and

  EXC_BREAKPOINT (SIGTRAP)
  Exception Type: EXC_BREAKPOINT (SIGTRAP)
  Exception Codes: KERN_INVALID_ADDRESS
  Crashed in: __exceptionPreprocess

  Application Specific Information:
  Crashed during Objective-C exception handling

  Thread 0 Crashed:
  0   CoreFoundation                      0x19694540c __exceptionPreprocess
  1   Sentry.framework                    0x100becfe8 -[SentryWatchdogTerminationScopeObserver addSerializedBreadcrumb:] + 109
  2   Sentry.framework                    0x100c0a2c8 -[SentryScope addBreadcrumb:] + 142
  3   Sentry.framework                    0x10f33434c __SentryNativeBridgeAddBreadcrumb_block_invoke + 85
  4   Sentry.framework                    0x100bdd7cc -[SentryHub configureScope:] + 609
  5   Sentry.framework                    0x100c09224 +[SentrySDK configureScope:] + 457
  6   Sentry.framework                    0x10f3341c8 SentryNativeBridgeAddBreadcrumb + 65
  7   Sentry.framework                    0x116352448 SentryCocoaBridgeProxy_AddBreadcrumb + 1787
  8   Sentry.framework                    0x116352448 NativeScopeObserver_AddBreadcrumbImpl + 1139
  9   Sentry.framework                    0x11633e034 ScopeObserver_AddBreadcrumb + 14295
  10  Sentry.framework                    0x11627037c Scope_AddBreadcrumb + 15643
  11  Sentry.framework                    0x11626faac HubExtensions_AddBreadcrumb + 12809
  12  Sentry.framework                    0x11626f870 HubExtensions_AddBreadcrumb + 12738
  13  Sentry.framework                    0x11634fc9c UnityApplicationLoggingIntegration_OnLogMessageReceived + 29343
  14  libsystem_pthread                   0x1e16ec0e8 _pthread_start

Here SentryWatchdogTerminationScopeObserver.addSerializedBreadcrumb encounters an exception while serializing breadcrumb data.

Proposal

A two-step approach:

Date Formatting

Instead of treating NSCalendarIdentifierISO8601 as a string (which it is not see docs) and setting it in

[dateFormatter setDateFormat:NSCalendarIdentifierISO8601];
we explicitly set the format.

Corrupted Breadcrumb Data

We preallocate and validate the strings passed into the bridge before handing it over to the Cocoa SDK.

@bitsandfoxes bitsandfoxes changed the title fix: Preallocate NSString in native bridge fix: Breadcrumb issues in Apple native bridge Sep 22, 2025
Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we add some tests for this new functionality? Are there any?

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing stopping me from approving this is tests. The PR changes the logic a bit. I'm pretty sure we could write some tests that reproduce the problem. What's stopping us from adding these?

@bitsandfoxes
Copy link
Contributor Author

The only thing stopping me from approving this is tests.

We don't have any unit tests for the bridge but instead, cover this via SmokeTester when running the game on simulator in CI. I've added the new removal flow through the bridge to the tester.

cursor[bot]

This comment was marked as outdated.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @bitsandfoxes

breadcrumb.timestamp =
[dateFormatter dateFromString:[NSString stringWithUTF8String:timestamp]];
if (timestampString != nil && timestampString.length > 0) {
breadcrumb.timestamp = [sentry_cachedISO8601Formatter() dateFromString:timestampString];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes indeed ⬆️

@bitsandfoxes bitsandfoxes merged commit d43d51b into main Sep 24, 2025
102 of 103 checks passed
@bitsandfoxes bitsandfoxes deleted the fix/native-bridge-alloc branch September 24, 2025 14:57
@philipphofmann
Copy link
Member

philipphofmann commented Sep 25, 2025

@bitsandfoxes did you address the comment of Cursor #2327

Screenshot 2025-09-25 at 11 39 14

I don't see any commits after my review, or am I missing something?

@bitsandfoxes
Copy link
Contributor Author

bitsandfoxes commented Sep 25, 2025

Screenshot 2025-09-25 at 12 09 05

Oh this looks completely different to me. I thought you were agreeing with the change!
Let me follow up on this.

@philipphofmann
Copy link
Member

Ups sorry, I could have been clearer with my wording. I'm sorry about the hassle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants