Skip to content

Commit

Permalink
Fix IOS crash in Network Plugin due to incorrect processing of data U… (
Browse files Browse the repository at this point in the history
#978)

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

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
Pull Request resolved: #978

Test Plan:
1. `npx react-native init issue974 --version [email protected]`
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](https://github.com/facebook/flipper/files/4434063/rn-data-uri-test.patch.txt)

Reviewed By: mweststrate

Differential Revision: D20861168

Pulled By: cekkaewnumchai

fbshipit-source-id: bae960650ecc0efbb8ae4641aba4c62c74f06bf0
  • Loading branch information
mark-plukkido authored and facebook-github-bot committed Apr 8, 2020
1 parent 1a794c5 commit e44c7f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ - (void)didObserveRequest:(SKRequestInfo*)request {
}

- (void)didObserveResponse:(SKResponseInfo*)response {
// Only track HTTP(S) calls, data URLs cannot be casted to NSHTTPURLResponse
if (![response.response isKindOfClass:[NSHTTPURLResponse class]]) {
return;
}

NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response.response;

NSMutableArray<NSDictionary<NSString*, id>*>* headers = [NSMutableArray new];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]]) {
return YES;
}

NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
NSString* contentType = httpResponse.allHeaderFields[@"content-type"];
if (!contentType) {
Expand Down

0 comments on commit e44c7f4

Please sign in to comment.