summaryrefslogtreecommitdiffstats
path: root/luni/src
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2015-04-07 12:29:49 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-04-07 12:29:50 +0000
commite25881196b4cb5f056619bf2883b10bb861dd704 (patch)
tree8ae52daeb1bd532b69cf70cb2085e6c0b8719f3e /luni/src
parent2dbbb9e769a075ad07b7ee811be645b2e06ad40d (diff)
parentb6d280493ffca2b63c7b850360309521af2b962e (diff)
downloadlibcore-e25881196b4cb5f056619bf2883b10bb861dd704.zip
libcore-e25881196b4cb5f056619bf2883b10bb861dd704.tar.gz
libcore-e25881196b4cb5f056619bf2883b10bb861dd704.tar.bz2
Merge "GZIPInputStream: Correctly handle extras in gzip headers."
Diffstat (limited to 'luni/src')
-rw-r--r--luni/src/main/java/java/util/zip/GZIPInputStream.java2
-rw-r--r--luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java16
2 files changed, 17 insertions, 1 deletions
diff --git a/luni/src/main/java/java/util/zip/GZIPInputStream.java b/luni/src/main/java/java/util/zip/GZIPInputStream.java
index afbbafe..925e8c4 100644
--- a/luni/src/main/java/java/util/zip/GZIPInputStream.java
+++ b/luni/src/main/java/java/util/zip/GZIPInputStream.java
@@ -222,7 +222,7 @@ public class GZIPInputStream extends InflaterInputStream {
if (hcrc) {
crc.update(header, 0, 2);
}
- int length = Memory.peekShort(scratch, 0, ByteOrder.LITTLE_ENDIAN) & 0xffff;
+ int length = Memory.peekShort(header, 0, ByteOrder.LITTLE_ENDIAN) & 0xffff;
while (length > 0) {
int max = length > scratch.length ? scratch.length : length;
int result = in.read(scratch, 0, max);
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 153f324..5813753 100644
--- a/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java
+++ b/luni/src/test/java/libcore/java/util/zip/GZIPInputStreamTest.java
@@ -51,6 +51,18 @@ public final class GZIPInputStreamTest extends TestCase {
-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 {@code HELLO_WORLD_GZIPPED} except that the 4th header byte is 4
+ * (FEXTRA flag) and that the 8 bytes after the header make up the extra.
+ *
+ * Constructed manually because none of the commonly used tools appear to emit header CRCs.
+ */
+ private static final byte[] HELLO_WORLD_GZIPPED_WITH_EXTRA = new byte[] {
+ 31, -117, 8, 4, 0, 0, 0, 0, 0, 0, // 10 byte header
+ 6, 0, 4, 2, 4, 2, 4, 2, // 2 byte extra length + 6 byte extra.
+ -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"));
}
@@ -59,6 +71,10 @@ public final class GZIPInputStreamTest extends TestCase {
assertEquals("Hello World", new String(gunzip(HELLO_WORLD_GZIPPED_WITH_HEADER_CRC), "UTF-8"));
}
+ public void testShortMessageWithHeaderExtra() throws IOException {
+ assertEquals("Hello World", new String(gunzip(HELLO_WORLD_GZIPPED_WITH_EXTRA), "UTF-8"));
+ }
+
public void testLongMessage() throws IOException {
byte[] data = new byte[1024 * 1024];
new Random().nextBytes(data);