getsentry / sentry-cocoa

The official Sentry SDK for iOS, tvOS, macOS, watchOS.
https://sentry.io/for/cocoa/
MIT License
803 stars 316 forks source link

Invalid `NSError` object can cause crash #4143

Closed dohyeondk closed 2 months ago

dohyeondk commented 3 months ago

Platform

iOS

Environment

Production

Installed

Swift Package Manager

Version

8.30.0

Xcode Version

15.4

Did it work on previous versions?

No response

Steps to Reproduce

  1. Install Sentry SDK and set up
  2. Initialize Sentry
  3. Send NSError with a userInfo dictionary containing a bad value for the key, NSUnderlyingErrorKey . E.g. userInfo: [NSUnderlyingErrorKey: "garbage"]

For example,

import Sentry

func application(_ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

    SentrySDK.start { options in
        ...
    }

    let error = NSError(domain: ..., code: ..., userInfo: [NSUnderlyingErrorKey: "garbage"])
    SentrySDK.capture(error: error)

    return true
}

Expected Result

Sentry sends the error information successfully.

Actual Result

The app crashes.

Are you willing to submit a PR?

Yes

dohyeondk commented 3 months ago

We found this issue while integrating Sentry SDK into our iOS app. We are receiving NSError from the other parts, and sometimes we cannot guarantee the validity of userInfo always.

krystofwoldrich commented 3 months ago

Thank you @dohyeondk and @jmkrein for the message and the PR.

We will review the the linked PR shorly.