Skip to content

Commit

Permalink
Catch exception when opening an ExifInterface for a non-jpeg
Browse files Browse the repository at this point in the history
Summary:
Fixes #1558 and #1760.

When a local file is loaded an attempt is made to load the thumbnail from its exif data but that is only available for JPEGs.

Trying the same with a PNG lead to an `IOException` which wasn't being caught within the producer. Catching it allows us to return null which is the appropriate thing to do if no thumbnail is available.

Reviewed By: erikandre

Differential Revision: D5077525

fbshipit-source-id: fdfd8e0bc369e4672729c6e3bfde5b035f836149
  • Loading branch information
kirwan authored and facebook-github-bot committed May 17, 2017
1 parent 4f3796b commit 81334f1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

package com.facebook.imagepipeline.producers;

import javax.annotation.Nullable;

import java.io.File;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.Executor;

import android.content.ContentResolver;
import android.database.Cursor;
import android.media.ExifInterface;
import android.net.Uri;
import android.provider.MediaStore;
import android.util.Pair;

import com.facebook.common.internal.ImmutableMap;
Expand Down Expand Up @@ -130,10 +130,14 @@ public void onCancellationRequested() {
mExecutor.execute(cancellableProducerRunnable);
}

@VisibleForTesting ExifInterface getExifInterface(Uri uri) throws IOException {
@VisibleForTesting @Nullable ExifInterface getExifInterface(Uri uri) {
final String realPath = UriUtil.getRealPathFromUri(mContentResolver, uri);
if (canReadAsFile(realPath)) {
try {
if (canReadAsFile(realPath)) {
return new ExifInterface(realPath);
}
} catch (IOException e) {
// If we cannot get the exif interface, return null as there is no thumbnail available
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private TestLocalExifThumbnailProducer(
}

@Override
ExifInterface getExifInterface(Uri uri) throws IOException {
ExifInterface getExifInterface(Uri uri) {
if (uri.equals(mUri)) {
return mExifInterface;
}
Expand Down

0 comments on commit 81334f1

Please sign in to comment.