From 6d64892c8a04ed01e693b9bd1997db9e347e0cee Mon Sep 17 00:00:00 2001 From: Ben Roth Date: Thu, 14 Sep 2017 11:54:41 -0700 Subject: [PATCH] Fix crash when trying to load photo library assets with nil image url Summary: This avoids a crash when we try to load a PHAsset with nil image url. Specifically, the following condition evaluates to true when `imageURL` is nil: ```objc if ([imageURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame) { assetID = [imageURL absoluteString]; results = [PHAsset fetchAssetsWithALAssetURLs:@[imageURL] options:nil]; } ``` The crash will be "attempt to insert nil object from objects[0]" when we build the `@[imageURL]` array literal. We've seen this emerge as a very common crash among Expo users, so I wanted to at least provide a clear error message instead of terminating the app. Load an image from the photo library with a nil request url. Closes https://github.com/facebook/react-native/pull/15952 Differential Revision: D5835219 Pulled By: ericnakagawa fbshipit-source-id: 7be00a15e674a0905cf5c27c526ce9085d1b308f --- Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m b/Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m index b99ac934fed..0c2adb7f520 100644 --- a/Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m +++ b/Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m @@ -44,7 +44,10 @@ RCT_EXPORT_MODULE() // form of an, NSURL which is what assets-library uses. NSString *assetID = @""; PHFetchResult *results; - if ([imageURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame) { + if (!imageURL) { + completionHandler(RCTErrorWithMessage(@"Cannot load a photo library asset with no URL"), nil); + return ^{}; + } else if ([imageURL.scheme caseInsensitiveCompare:@"assets-library"] == NSOrderedSame) { assetID = [imageURL absoluteString]; results = [PHAsset fetchAssetsWithALAssetURLs:@[imageURL] options:nil]; } else {