diff options
author | Narayan Kamath <narayan@google.com> | 2015-04-03 15:55:01 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2015-04-03 15:55:02 +0000 |
commit | e54ee76fd7aec2c0f7bb09a99401660dc69818db (patch) | |
tree | c00d36d4c9ce9131c5d467b20d06d60b534898f3 | |
parent | 608f2b1df282913c58fcfd56abda11e4e3e4ff63 (diff) | |
parent | fe3469f59ea823c2ddb2671a4fe0568b25c83df6 (diff) | |
download | libcore-e54ee76fd7aec2c0f7bb09a99401660dc69818db.zip libcore-e54ee76fd7aec2c0f7bb09a99401660dc69818db.tar.gz libcore-e54ee76fd7aec2c0f7bb09a99401660dc69818db.tar.bz2 |
Merge "GZIPInputStream: Fix handling of header CRCs."
-rw-r--r-- | luni/src/main/java/java/util/zip/GZIPInputStream.java | 2 | ||||
-rw-r--r-- | luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java | 20 |
2 files changed, 19 insertions, 3 deletions
diff --git a/luni/src/main/java/java/util/zip/GZIPInputStream.java b/luni/src/main/java/java/util/zip/GZIPInputStream.java index 1bfc496..afbbafe 100644 --- a/luni/src/main/java/java/util/zip/GZIPInputStream.java +++ b/luni/src/main/java/java/util/zip/GZIPInputStream.java @@ -243,7 +243,7 @@ public class GZIPInputStream extends InflaterInputStream { } if (hcrc) { Streams.readFully(in, header, 0, 2); - short crc16 = Memory.peekShort(scratch, 0, ByteOrder.LITTLE_ENDIAN); + short crc16 = Memory.peekShort(header, 0, ByteOrder.LITTLE_ENDIAN); if ((short) crc.getValue() != crc16) { throw new IOException("CRC mismatch"); } diff --git a/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java b/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java index 494520a..153f324 100644 --- a/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java +++ b/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java @@ -35,14 +35,30 @@ import libcore.io.Streams; public final class GZIPInputStreamTest extends TestCase { private static final byte[] HELLO_WORLD_GZIPPED = new byte[] { - 31, -117, 8, 0, 0, 0, 0, 0, 0, 0, -13, 72, -51, -55, -55, 87, 8, -49, - 47, -54, 73, 1, 0, 86, -79, 23, 74, 11, 0, 0, 0 + 31, -117, 8, 0, 0, 0, 0, 0, 0, 0, // 10 byte header + -13, 72, -51, -55, -55, 87, 8, -49, 47, -54, 73, 1, 0, 86, -79, 23, 74, 11, 0, 0, 0 // data + }; + + /** + * This is the same as the above, except that the 4th header byte is 2 (FHCRC flag) + * and the 2 bytes after the header make up the CRC. + * + * Constructed manually because none of the commonly used tools appear to emit header CRCs. + */ + private static final byte[] HELLO_WORLD_GZIPPED_WITH_HEADER_CRC = new byte[] { + 31, -117, 8, 2, 0, 0, 0, 0, 0, 0, // 10 byte header + 29, 38, // 2 byte CRC. + -13, 72, -51, -55, -55, 87, 8, -49, 47, -54, 73, 1, 0, 86, -79, 23, 74, 11, 0, 0, 0 // data }; public void testShortMessage() throws IOException { assertEquals("Hello World", new String(gunzip(HELLO_WORLD_GZIPPED), "UTF-8")); } + public void testShortMessageWithCrc() throws IOException { + assertEquals("Hello World", new String(gunzip(HELLO_WORLD_GZIPPED_WITH_HEADER_CRC), "UTF-8")); + } + public void testLongMessage() throws IOException { byte[] data = new byte[1024 * 1024]; new Random().nextBytes(data); |