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 crash in Network Plugin due to incorrect processing of data U… #978

Closed
wants to merge 3 commits into from
Closed

Conversation

mark-plukkido
Copy link
Contributor

@mark-plukkido mark-plukkido commented Apr 5, 2020

Fix IOS crash in Network Plugin due to incorrect processing of data URLs (#974)

Summary

Fix #974 by skipping response processing in FlipperKitNetworkPlugin.mm if the response is not an instance of NSHTTPURLResponse, which data URLs are not. My assumption is that data URLs are not the ones Flipper Network Plugin users are interested in, given the type of information being extracted in the didObserveResponse method which are only present in NSHTTPURLReponse types.

Changelog

Fix IOS crash in Network Plugin due to unchecked casting of data URLs

Test plan

  1. npx react-native init issue974 --version react-native@0.62.1
  2. cd issue974/ios/Pods/FlipperKit/iOS/Plugins/
  3. curl -L https://patch-diff.githubusercontent.com/raw/facebook/flipper/pull/978.patch | git apply -v -p3
  4. cd ../../../../../
  5. curl -L https://github.com/facebook/flipper/files/4434063/rn-data-uri-test.patch.txt | git apply -v react-native run-ios
  6. Verify that the app does not crash the IOS app with
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[NSURLResponse allHeaderFields]: unrecognized selector sent to instance <memaddr>'

The React Native app patch used to verify the PR working and resolving the issue #974

rn-data-uri-test.patch.txt

…RLs (#974)

Summary:
Fix #974 by skipping response processing in FlipperKitNetworkPlugin.mm
if the response is not an instance of NSHTTPURLResponse, which data URLs are not. My assumption is that data URLs
are not the ones Flipper Network Plugin users are interested in, given the type of information being extracted in
the didObserveResponse method which are only present in NSHTTPURLReponse types.
@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Apr 5, 2020
@mark-plukkido mark-plukkido marked this pull request as ready for review April 5, 2020 14:54
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@cekkaewnumchai has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@cekkaewnumchai
Copy link
Contributor

Thank you for the PR!

@@ -29,6 +29,11 @@ - (instancetype)initWithIndentifier:(int64_t)identifier
}

+ (BOOL)shouldStripReponseBodyWithResponse:(NSURLResponse*)response {
// Only HTTP(S) responses have Content-Type headers
if (![response isKindOfClass:[NSHTTPURLResponse class]]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering it this shouldn't return YES instead, given that this method returns if the response data should be stripped from the network request details, which is the case for large binary data as images, videos and zips. I can imagine we don't want to send the details fo data: urls to Flipper either? (see also line 50)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. I updated this PR.

@facebook-github-bot
Copy link
Contributor

@mark-plukkido has updated the pull request. Re-import the pull request

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@cekkaewnumchai has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@mark-plukkido mark-plukkido deleted the issue-974 branch April 8, 2020 10:27
@facebook-github-bot
Copy link
Contributor

@cekkaewnumchai merged this pull request in e44c7f4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

iOS - Network plugin - Crash when response is not an instance of NSHTTPURLResponse
4 participants