-
Bug
-
Resolution: Fixed
-
P2
-
6u23, 6u24
-
b08
-
x86
-
linux, windows_xp, windows_7
-
Verified
FULL PRODUCT VERSION :
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.32-27-generic #49-Ubuntu SMP
A DESCRIPTION OF THE PROBLEM :
Can no longer use java.util.zip.GZIPInputStream to read gzip files with extra fields. It looks like you're trying to skip the extra fields twice.
from java source code in java.util.zip.GZIPInputStream method readHeader:
// Skip MTIME, XFL, and OS fields
skipBytes(in, 6);
int n = 2 + 2 + 6;
// Skip optional extra field
if ((flg & FEXTRA) == FEXTRA) {
skipBytes(in, readUShort(in)); //<-BAD, attempted double skip
int m = readUShort(in); //<- other skip
skipBytes(in, m); //<-
n += m + 2;
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Heres a tiny example
$ echo -n 'H4sIBAAAAAAA/wYAQkMCADIAS0ksTuNKSyxO4UqtSC4pSuQqLilNS+MCAI56o3cXAAAAH4sIBAAAAAAA/wYAQkMCABsAAwAAAAAAAAAAAA==' | base64 -d > gggg2.gz
$ file gggg2.gz
gggg2.gz: gzip compressed data, extra field
$ zcat gggg2.gz
dasf
fasd
exctra
stuff
$ java Test gggg2.gz
Exception in thread "main" java.io.EOFException
at java.util.zip.GZIPInputStream.skipBytes(GZIPInputStream.java:270)
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:159)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:67)
at Test.main(Test.java:7)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
$ /usr/local/java/jdk1.6.0_22/bin/java Test gggg2.gz
dasf
fasd
exctra
stuff
ACTUAL -
$ java Test gggg2.gz
Exception in thread "main" java.io.EOFException
at java.util.zip.GZIPInputStream.skipBytes(GZIPInputStream.java:270)
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:159)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:67)
at Test.main(Test.java:7)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.zip.*;
public class Test {
public static void main(String args[]) throws IOException {
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(args[0]));
int len;
byte[] buf = new byte[1024];
while ((len = gzis.read(buf)) != -1) {
System.out.print(new String(buf, 0, len));
}
System.out.println();
}
}
---------- END SOURCE ----------
java version "1.6.0_23"
Java(TM) SE Runtime Environment (build 1.6.0_23-b05)
Java HotSpot(TM) 64-Bit Server VM (build 19.0-b09, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux 2.6.32-27-generic #49-Ubuntu SMP
A DESCRIPTION OF THE PROBLEM :
Can no longer use java.util.zip.GZIPInputStream to read gzip files with extra fields. It looks like you're trying to skip the extra fields twice.
from java source code in java.util.zip.GZIPInputStream method readHeader:
// Skip MTIME, XFL, and OS fields
skipBytes(in, 6);
int n = 2 + 2 + 6;
// Skip optional extra field
if ((flg & FEXTRA) == FEXTRA) {
skipBytes(in, readUShort(in)); //<-BAD, attempted double skip
int m = readUShort(in); //<- other skip
skipBytes(in, m); //<-
n += m + 2;
}
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Heres a tiny example
$ echo -n 'H4sIBAAAAAAA/wYAQkMCADIAS0ksTuNKSyxO4UqtSC4pSuQqLilNS+MCAI56o3cXAAAAH4sIBAAAAAAA/wYAQkMCABsAAwAAAAAAAAAAAA==' | base64 -d > gggg2.gz
$ file gggg2.gz
gggg2.gz: gzip compressed data, extra field
$ zcat gggg2.gz
dasf
fasd
exctra
stuff
$ java Test gggg2.gz
Exception in thread "main" java.io.EOFException
at java.util.zip.GZIPInputStream.skipBytes(GZIPInputStream.java:270)
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:159)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:67)
at Test.main(Test.java:7)
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
$ /usr/local/java/jdk1.6.0_22/bin/java Test gggg2.gz
dasf
fasd
exctra
stuff
ACTUAL -
$ java Test gggg2.gz
Exception in thread "main" java.io.EOFException
at java.util.zip.GZIPInputStream.skipBytes(GZIPInputStream.java:270)
at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:159)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:58)
at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:67)
at Test.main(Test.java:7)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.zip.*;
public class Test {
public static void main(String args[]) throws IOException {
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream(args[0]));
int len;
byte[] buf = new byte[1024];
while ((len = gzis.read(buf)) != -1) {
System.out.print(new String(buf, 0, len));
}
System.out.println();
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-7010399 Bug in GZip extraction
-
- Closed
-
-
JDK-7022417 JDK6u23,6u24 GZIPInputStream readHeader broke handling of GZIP 'extra fields'
-
- Closed
-
-
JDK-7028902 Broken some gzip files unpacking
-
- Closed
-