Skip to content

fix(ios): guard against nil markOpts and request to prevent EXC_BREAKPOINT crashes#271

Open
jtyreman-skewb wants to merge 1 commit intoJimmyDaddy:masterfrom
jtyreman-skewb:fix/ios-guard-nil-opts-and-request
Open

fix(ios): guard against nil markOpts and request to prevent EXC_BREAKPOINT crashes#271
jtyreman-skewb wants to merge 1 commit intoJimmyDaddy:masterfrom
jtyreman-skewb:fix/ios-guard-nil-opts-and-request

Conversation

@jtyreman-skewb
Copy link
Copy Markdown

Problem

Three force-unwrap sites in ImageMarker.swift cause EXC_BREAKPOINT (trap) crashes in production:

1 & 2 — Missing return after nil check in mark(withText:) and mark(withImage:)

Both methods check checkTextParams/checkImageParams for nil but don't return afterwards, so execution falls through into the Task block. Inside the task, markOpts is force-unwrapped:

// mark(withText:)
let images = try await loadImages(with: [(markOpts?.backgroundImage)!])  // 💥 EXC_BREAKPOINT
let scaledImage = self.markImgWithText(images[0], markOpts!)              // 💥 EXC_BREAKPOINT

// mark(withImage:)
var images = try await loadImages(with: [(markOpts?.backgroundImage)!] + waterImages!)  // 💥
let scaledImage = self.markImage(with: ..., options: markOpts!)                          // 💥

3 — Force-unwrap of request in loadImages

RCTConvert.nsurlRequest(img.src) returns an optional and can be nil for malformed URLs. It is immediately force-unwrapped:

let request = RCTConvert.nsurlRequest(img.src)
imageLoader.loadImage(with: request!, ...)  // 💥 EXC_BREAKPOINT if request is nil

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 let bindings that properly reject the JS promise with descriptive error messages instead of crashing:

  • mark(withText:) / mark(withImage:): use guard let markOpts = ... else { rejecter(...); return } before the Task block
  • loadImages: use guard let request = ... else { continuation.resume(throwing: error); return }
  • Remove ! force-unwraps on scaledImage, waterImages, and markOpts throughout both mark methods

Testing

  • Pass invalid/nil opts to markText or markImage — the JS catch block now receives a proper error instead of crashing
  • Pass a malformed image URL to either mark method — handled gracefully
  • Normal watermarking flow is unaffected

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.

1 participant