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

Add second check for position values (iOS) #296

Merged
merged 1 commit into from
May 15, 2020

Conversation

JamesCrowMedia
Copy link
Contributor

This PR resolves #295

What was causing the issue?

In www/plugins.FileOpener2.js:

When calling showOpenWithDialog without an optional callbackContext object, an empty object is set by default in the JS bridge:

line 37		callbackContext = callbackContext || {};

When the exec function is called, the missing position data is then referenced in the arguments array, resulting in an undefined value:

line 38		[fileName, contentType, false, callbackContext.position]

In src/ios/FileOpener2.m:

The undefined data is interpreted as a NSNull object and still placed in the array.
Screen Shot 2020-05-14 at 6 54 39 PM

On line 86, there is a check for array length, but not a check to see if the object is valid. This means positionValues on line 87, which should be a 2 item array, is a NSNull object instead. When the expected array items are accessed on line 88, this causes a NSInvalidArgumentException.

line 86		if ([command.arguments count] >= 4) {
line 87			NSArray *positionValues = [command.arguments objectAtIndex:3];
line 88			rect = CGRectMake(0, 0, [[positionValues objectAtIndex:0] floatValue], [[positionValues objectAtIndex:1] floatValue]);

How does this PR correct this issue?

This PR adds a second check to the if statement on line 86 to make sure the item at index 3 in not NSNull.

&& ![[command.arguments objectAtIndex:3] isEqual: [NSNull null]]

Optional position value is NSNull in arguments array when not included.
@pwlin pwlin merged commit 12c45da into pwlin:master May 15, 2020
@pwlin
Copy link
Owner

pwlin commented May 15, 2020

@JamesCrowMedia Thanks!

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.

Calling showOpenWithDialog on iOS without Position values results in a crash
2 participants