Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): Prevent infinite value in returned location data causing app crash #231

Merged
merged 1 commit into from Aug 1, 2022

Conversation

dpa99c
Copy link
Contributor

@dpa99c dpa99c commented Jul 16, 2021

Platforms affected

iOS

Motivation and Context

As outlined in #230, the plugin is sometimes causing app crashes on iOS 14 because one of the values being extracted from the native location object has an infinite value and therefore an exception is raised when trying to extract the values and transform then into a JSON object.

Description

Check the NSMutableDictionary constructed from the native CLLocation data is valid for conversion to JSON using isValidJSONObject before attempting conversion.

Testing

As outlined in #230, I'm not certain exactly which value retrieved from the CLLocation object is INFINITY because the stack trace from the crash only points to the line where the conversion to JSON is attempted but doesn't actually indicate which field in the NSMutableDictionary contains the INFINITE value.

However, the issue can be artificially reproduced by setting one of the values to INFINITY before the conversion is made, e.g. on line 293 of CDVLocation.m:

[returnInfo setObject:[NSNumber numberWithDouble:INFINITY] forKey@"timestamp"];

Without the changes this PR makes, the above will cause an app crash.
With the changes this PR makes, the plugin will return a POSITIONUNAVAILABLE error and the app will not crash.

Checklist

  • I've run the tests to see all new and existing tests pass
  • [N/A] I added automated test coverage as appropriate for this change
  • Commit is prefixed with (platform) if this change only applies to one platform (e.g. (android))
  • If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
  • [N/A] I've updated the documentation if necessary

Copy link
Contributor

@breautek breautek left a comment

Choose a reason for hiding this comment

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

lgtm

@jcesarmobile jcesarmobile changed the title (ios) fix: Prevent infinite value in returned location data causing app crash. Fixes #230. fix(ios): Prevent infinite value in returned location data causing app crash Jun 2, 2022
… is valid for conversion to JSON before attempting conversion.

Prevents crashes due to values invalid for JSON conversion such as INFINITY.
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.

None yet

3 participants