Defend against nil pointer in RCTImageLoader.m

Summary:
Defend against nil pointer in RCTImageLoader.m. In some rare case, the "response" might be nil, and this would lead to crash.

This issue is related: https://github.com/facebook/react-native/issues/6952
Closes https://github.com/facebook/react-native/pull/8141

Differential Revision: D3579427

Pulled By: javache

fbshipit-source-id: 7b71768a0c6d74a42d280b1d54adda86b493f0ef
This commit is contained in:
yeshuang 2016-07-18 04:45:11 -07:00 committed by Facebook Github Bot 8
parent df8c88e000
commit ca5d1aebab
1 changed files with 13 additions and 2 deletions

View File

@ -382,6 +382,9 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image,
if (error) {
completionHandler(error, nil);
return;
} else if (!response) {
completionHandler(RCTErrorWithMessage(@"Response metadata error"), nil);
return;
} else if (!data) {
completionHandler(RCTErrorWithMessage(@"Unknown image download error"), nil);
return;
@ -435,8 +438,16 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image,
// Download image
__weak __typeof(self) weakSelf = self;
RCTNetworkTask *task = [networking networkTaskWithRequest:request completionBlock:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
completionHandler(error, nil);
if (error || !response || !data) {
NSError *someError = nil;
if (error) {
someError = error;
} else if (!response) {
someError = RCTErrorWithMessage(@"Response metadata error");
} else {
someError = RCTErrorWithMessage(@"Unknown image download error");
}
completionHandler(someError, nil);
[weakSelf dequeueTasks];
return;
}