Repository navigation
fix: Handle nil URL in NSData swizzling - #9535
Merged
Merged
Conversation
Objective-C callers such as MessageUI can read NSData from a nil URL. The swizzled initWithContentsOfURL:options:error: forwarded it to SentryFileIOTracker, whose Swift URL parameter is non-optional, so bridging nil trapped with EXC_BREAKPOINT. Call the original implementation untracked when the URL is nil. Fixes #9519 Fixes COCOA-2144
itaybre
requested review from
NinjaLikesCheez and
philprime
and removed request for
a team
November 4, 2026 18:57
itaybre
enabled auto-merge (squash)
November 5, 2026 14:01
Size Analysis1 component analyzed iOS Builds
|
📲 Install BuildsiOS
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
The swizzled
-[NSData initWithContentsOfURL:options:error:]now calls the original implementation without tracking when the URL isnil.Objective-C callers can pass a
nilURL. MessageUI does this when sharing an attachment to Mail (-[MFAttachmentSecurityScope data]→+[NSData dataWithContentsOfURL:options:error:]). The swizzle forwarded thenilURL toSentryFileIOTracker.measureNSData(from:...). That method takes a non-optional SwiftURL, soURL._unconditionallyBridgeFromObjectiveCtrapped withEXC_BREAKPOINT.The
NSStringpath swizzles aren't affected, because Swift bridges anilNSStringto an emptyString.💡 Motivation and Context
Fixes #9519
Fixes COCOA-2144
💚 How did you test it?
testInitWithContentsOfURLOptionsError_whenURLIsNil_shouldCallOriginalWithoutTracking. It calls+dataWithContentsOfURL:options:error:withnilthrough its IMP.nilURL depends on the OS: the macOS 26 test host raisesNSInvalidArgumentException. The test therefore checks that the swizzled call has the same outcome as the unswizzled call and doesn't reach the tracker.SentryNSDataSwizzlingHelperTests,DataSentryTracingIntegrationTests, andSentryFileIOTrackerTestspass on macOS and iOS.make formatandmake analyzepass.📝 Checklist
sendDefaultPIIis enabled.