Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 203ed4d5 authored by Jaesung Chung's avatar Jaesung Chung Committed by Android (Google) Code Review
Browse files

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

parents 01e236b9 42ac0d00
Loading
Loading
Loading
Loading
+2 −8
Original line number Diff line number Diff line
@@ -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;
+5 −3
Original line number Diff line number Diff line
@@ -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!");
        }
    }