fix(ios): guard against nil markOpts and request to prevent EXC_BREAKPOINT crashes#271
Open
jtyreman-skewb wants to merge 1 commit intoJimmyDaddy:masterfrom
Open
Conversation
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.
Problem
Three force-unwrap sites in
ImageMarker.swiftcauseEXC_BREAKPOINT(trap) crashes in production:1 & 2 — Missing
returnafter nil check inmark(withText:)andmark(withImage:)Both methods check
checkTextParams/checkImageParamsfor nil but don'treturnafterwards, so execution falls through into theTaskblock. Inside the task,markOptsis force-unwrapped:3 — Force-unwrap of
requestinloadImagesRCTConvert.nsurlRequest(img.src)returns an optional and can benilfor malformed URLs. It is immediately force-unwrapped:These crashes are observed in production on iOS 17+ with React Native 0.73+ (both old and new architecture).
Fix
Replace all three force-unwrap patterns with
guard letbindings that properly reject the JS promise with descriptive error messages instead of crashing:mark(withText:)/mark(withImage:): useguard let markOpts = ... else { rejecter(...); return }before theTaskblockloadImages: useguard let request = ... else { continuation.resume(throwing: error); return }!force-unwraps onscaledImage,waterImages, andmarkOptsthroughout both mark methodsTesting
optstomarkTextormarkImage— the JScatchblock now receives a proper error instead of crashing