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

am: 203ed4d5

* commit '203ed4d50070beaaa463b87d367613da6b7d2ee1':
  ExifInterface: fix regression of re-writing JPEG
This commit is contained in:
Jaesung Chung
2016-03-23 02:36:13 +00:00
committed by android-build-merger
2 changed files with 7 additions and 11 deletions

View File

@@ -1191,10 +1191,6 @@ public class ExifInterface {
++bytesRead; ++bytesRead;
while (true) { while (true) {
marker = dataInputStream.readByte(); marker = dataInputStream.readByte();
if (marker == -1) {
Log.w(TAG, "Reading JPEG has ended unexpectedly");
break;
}
if (marker != MARKER) { if (marker != MARKER) {
throw new IOException("Invalid marker:" + Integer.toHexString(marker & 0xff)); throw new IOException("Invalid marker:" + Integer.toHexString(marker & 0xff));
} }
@@ -1329,10 +1325,6 @@ public class ExifInterface {
while (true) { while (true) {
byte marker = dataInputStream.readByte(); byte marker = dataInputStream.readByte();
if (marker == -1) {
Log.w(TAG, "Reading JPEG has ended unexpectedly");
break;
}
if (marker != MARKER) { if (marker != MARKER) {
throw new IOException("Invalid marker"); throw new IOException("Invalid marker");
} }
@@ -1357,6 +1349,8 @@ public class ExifInterface {
} }
} }
// Copy non-EXIF APP1 segment. // Copy non-EXIF APP1 segment.
dataOutputStream.writeByte(MARKER);
dataOutputStream.writeByte(marker);
dataOutputStream.writeUnsignedShort(length + 2); dataOutputStream.writeUnsignedShort(length + 2);
if (length >= 6) { if (length >= 6) {
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); 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]; byte[] bytes = new byte[1024];
try { try {
new ExifInterface(new ByteArrayInputStream(bytes)); new ExifInterface(new ByteArrayInputStream(bytes));
fail("Should not reach here!"); // Always success
} catch (IOException e) { } catch (IOException e) {
// Success fail("Should not reach here!");
} }
} }