summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSungsoo <sungsoo@google.com>2016-08-23 14:48:43 +0900
committerThe Android Automerger <android-build@android.com>2016-09-27 00:15:04 -0700
commit73fdb1af54c396e87c5b7e07c6a84296f4bdb33b (patch)
treedecb28b66bd53acceb00f4ec57489ba0901cdd6e
parenta720961230e580f8163e80b0e3d4fa3105cab043 (diff)
downloadbase-73fdb1af54c396e87c5b7e07c6a84296f4bdb33b.tar.gz
DO NOT MERGE) ExifInterface: Make saveAttributes throw an exception before change
ExifInterface object can be created with a unsupported file format. If saveAttribute is called with an unsupported file format, ExifInterface makes the file corrupted. This CL prevents those cases by throwing an exception before making any change on the file. Bug: 30936376 Change-Id: I115a42601c774062485974042464abb0d65c35e9 (cherry picked from commit a8f9a075b14c526a0de75c2ade81ebc4e05e4ef8) (cherry picked from commit 56ea7b490107e4531ab4db6f74671c34b5c59fd3)
-rw-r--r--media/java/android/media/ExifInterface.java13
1 files changed, 8 insertions, 5 deletions
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java
index 4848630baacf..56af57aa8e96 100644
--- a/media/java/android/media/ExifInterface.java
+++ b/media/java/android/media/ExifInterface.java
@@ -679,14 +679,14 @@ public class ExifInterface {
if (value instanceof long[]) {
long[] array = (long[]) value;
if (array.length == 1) {
- return (double) array[0];
+ return array[0];
}
throw new NumberFormatException("There are more than one component");
}
if (value instanceof int[]) {
int[] array = (int[]) value;
if (array.length == 1) {
- return (double) array[0];
+ return array[0];
}
throw new NumberFormatException("There are more than one component");
}
@@ -1083,6 +1083,7 @@ public class ExifInterface {
private int mThumbnailOffset;
private int mThumbnailLength;
private byte[] mThumbnailBytes;
+ private boolean mIsSupportedFile;
// Pattern to check non zero timestamp
private static final Pattern sNonZeroTimePattern = Pattern.compile(".*[1-9].*");
@@ -1472,9 +1473,11 @@ public class ExifInterface {
// Process JPEG input stream
getJpegAttributes(in);
+ mIsSupportedFile = true;
} catch (IOException e) {
// Ignore exceptions in order to keep the compatibility with the old versions of
// ExifInterface.
+ mIsSupportedFile = false;
Log.w(TAG, "Invalid image: ExifInterface got an unsupported image format file"
+ "(ExifInterface supports JPEG and some RAW image formats only) "
+ "or a corrupted JPEG file to ExifInterface.", e);
@@ -1553,9 +1556,9 @@ public class ExifInterface {
* and make a single call rather than multiple calls for each attribute.
*/
public void saveAttributes() throws IOException {
- if (mIsRaw) {
+ if (!mIsSupportedFile || mIsRaw) {
throw new UnsupportedOperationException(
- "ExifInterface does not support saving attributes on RAW formats.");
+ "ExifInterface only supports saving attributes on JPEG formats.");
}
if (mIsInputStream || (mSeekableFileDescriptor == null && mFilename == null)) {
throw new UnsupportedOperationException(
@@ -2352,7 +2355,7 @@ public class ExifInterface {
for (int i = 0; i < EXIF_TAGS.length; ++i) {
int sum = 0;
for (Map.Entry entry : (Set<Map.Entry>) mAttributes[i].entrySet()) {
- final ExifAttribute exifAttribute = (ExifAttribute) ((Map.Entry) entry).getValue();
+ final ExifAttribute exifAttribute = (ExifAttribute) entry.getValue();
final int size = exifAttribute.size();
if (size > 4) {
sum += size;