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:
parent
df8c88e000
commit
ca5d1aebab
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue