Skip to content

Commit 23e6629

Browse files
Sungsoogitbuildkicker
authored andcommitted
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: I915f56b00ec9422b53591ac5534e070a1d6798e6 (cherry picked from commit 2ee53c8)
1 parent b8be33b commit 23e6629

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

media/java/android/media/ExifInterface.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,7 @@ private ExifTag(String name, int number, int primaryFormat, int secondaryFormat)
10391039
private int mThumbnailOffset;
10401040
private int mThumbnailLength;
10411041
private byte[] mThumbnailBytes;
1042+
private boolean mIsSupportedFile;
10421043

10431044
// Pattern to check non zero timestamp
10441045
private static final Pattern sNonZeroTimePattern = Pattern.compile(".*[1-9].*");
@@ -1337,9 +1338,11 @@ private void loadAttributes() throws IOException {
13371338
try {
13381339
InputStream in = new FileInputStream(mFilename);
13391340
getJpegAttributes(in);
1341+
mIsSupportedFile = true;
13401342
} catch (IOException e) {
13411343
// Ignore exceptions in order to keep the compatibility with the old versions of
13421344
// ExifInterface.
1345+
mIsSupportedFile = false;
13431346
Log.w(TAG, "Invalid image.", e);
13441347
} finally {
13451348
addDefaultValuesForCompatibility();
@@ -1368,6 +1371,10 @@ private void printAttributes() {
13681371
* and make a single call rather than multiple calls for each attribute.
13691372
*/
13701373
public void saveAttributes() throws IOException {
1374+
if (!mIsSupportedFile) {
1375+
throw new UnsupportedOperationException(
1376+
"ExifInterface only supports saving attributes on JPEG formats.");
1377+
}
13711378
// Keep the thumbnail in memory
13721379
mThumbnailBytes = getThumbnail();
13731380

0 commit comments

Comments
 (0)