Skip to content

Commit

Permalink
Fix crash when trying to load photo library assets with nil image url
Browse files Browse the repository at this point in the history
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 facebook#15952

Differential Revision: D5835219

Pulled By: ericnakagawa

fbshipit-source-id: 7be00a15e674a0905cf5c27c526ce9085d1b308f
  • Loading branch information
terribleben authored and ide committed Sep 14, 2017
1 parent 7491bc3 commit 1a3e388
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Libraries/CameraRoll/RCTPhotoLibraryImageLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ - (RCTImageLoaderCancellationBlock)loadImageForURL:(NSURL *)imageURL
// 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 {
Expand Down

0 comments on commit 1a3e388

Please sign in to comment.