Fixed threading issue in RCTImageLoader

Summary: This will probably not fix the crash but the current implementation certenly is/was not thread-safe.

Reviewed By: javache

Differential Revision: D9977538

fbshipit-source-id: a9cac05c313ff51efefbd7c228a1160a3aa75b54
This commit is contained in:
Valentin Shergin 2018-09-21 08:48:33 -07:00 committed by Facebook Github Bot
parent 023f0a6855
commit f409fd8d6e
1 changed files with 36 additions and 31 deletions

View File

@ -809,8 +809,9 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image,
// but we'd have to run the logic both in RCTPhotoLibraryImageLoader and
// RCTAssetsLibraryRequestHandler. Once we drop iOS7 though, we'd drop
// RCTAssetsLibraryRequestHandler and can move it there.
static NSRegularExpression *videoRegex = nil;
if (!videoRegex) {
static NSRegularExpression *videoRegex;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSError *error = nil;
videoRegex = [NSRegularExpression regularExpressionWithPattern:@"(?:&|^)ext=MOV(?:&|$)"
options:NSRegularExpressionCaseInsensitive
@ -818,12 +819,15 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image,
if (error) {
RCTLogError(@"%@", error);
}
}
});
NSString *query = requestURL.query;
if (query != nil && [videoRegex firstMatchInString:query
if (
query != nil &&
[videoRegex firstMatchInString:query
options:0
range:NSMakeRange(0, query.length)]) {
range:NSMakeRange(0, query.length)]
) {
return NO;
}
@ -836,6 +840,7 @@ static UIImage *RCTResizeImageIfNeeded(UIImage *image,
return YES;
}
}
return NO;
}