From 1043f56185ee4abb0246ebe44eea7e391802d4fa Mon Sep 17 00:00:00 2001 From: Jaesung Chung Date: Mon, 14 Mar 2016 15:09:09 +0900 Subject: [PATCH] ExifInterface: ignore exceptions when getting wrong images In order to maintain compatibility with the old versions of ExifInterface, non-JPEG image files, for instance, PNG, GIF and so on, need to be handled by generating an empty result rather than throwing an exception in the constructor. And corrupted JPG files also should be handled in the same way. Bug: 27587980 Change-Id: If33b63c683bfb672999d1abd370a8edf29932ac1 --- media/java/android/media/ExifInterface.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java index ce12e76b65880..3996004d02a55 100644 --- a/media/java/android/media/ExifInterface.java +++ b/media/java/android/media/ExifInterface.java @@ -824,7 +824,13 @@ public class ExifInterface { } // Process JPEG input stream - getJpegAttributes(in); + try { + getJpegAttributes(in); + } catch (IOException e) { + // Ignore exceptions in order to keep the compatibility with the old versions of + // ExifInterface. + Log.w(TAG, "Invalid JPEG", e); + } if (DEBUG) { printAttributes();