Merge "ExifInterface: fix regression of re-writing JPEG" into nyc-dev

This commit is contained in:
Jaesung Chung
2016-03-23 02:30:27 +00:00
committed by Android (Google) Code Review
2 changed files with 7 additions and 11 deletions

View File

@@ -1191,10 +1191,6 @@ public class ExifInterface {
++bytesRead;
while (true) {
marker = dataInputStream.readByte();
if (marker == -1) {
Log.w(TAG, "Reading JPEG has ended unexpectedly");
break;
}
if (marker != MARKER) {
throw new IOException("Invalid marker:" + Integer.toHexString(marker & 0xff));
}
@@ -1329,10 +1325,6 @@ public class ExifInterface {
while (true) {
byte marker = dataInputStream.readByte();
if (marker == -1) {
Log.w(TAG, "Reading JPEG has ended unexpectedly");
break;
}
if (marker != MARKER) {
throw new IOException("Invalid marker");
}
@@ -1357,6 +1349,8 @@ public class ExifInterface {
}
}
// Copy non-EXIF APP1 segment.
dataOutputStream.writeByte(MARKER);
dataOutputStream.writeByte(marker);
dataOutputStream.writeUnsignedShort(length + 2);
if (length >= 6) {
length -= 6;

View File

@@ -417,13 +417,15 @@ public class ExifInterfaceTest extends AndroidTestCase {
testExifInterfaceForRaw(LG_G4_ISO_800_DNG, R.array.lg_g4_iso_800_dng);
}
public void testCorruptedImage() throws Throwable {
public void testDoNotFailOnCorruptedImage() throws Throwable {
// To keep the compatibility with old versions of ExifInterface, even on a corrupted image,
// it shouldn't raise any exceptions except an IOException when unable to open a file.
byte[] bytes = new byte[1024];
try {
new ExifInterface(new ByteArrayInputStream(bytes));
fail("Should not reach here!");
// Always success
} catch (IOException e) {
// Success
fail("Should not reach here!");
}
}