JDK-7011162 : REGRESSION, incorrect header handling of extra gzip fields
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 6u23,6u24
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: linux,windows_xp,windows_7
  • CPU: x86
  • Submitted: 2011-01-09
  • Updated: 2012-05-31
  • Resolved: 2011-10-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6u30 b08Fixed
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Description
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 ----------

Comments
SUGGESTED FIX http://jpsesvr.sfbay.sun.com:8080/ctetools/html/ViewDetail.jsp?index=4119
14-06-2011

EVALUATION Failed backport of #4691425 (from jdk7 to 6u23). Not reproducible in jdk7. 6u23 diff: See ln#149/157 http://jpsesvr.sfbay.sun.com:8080/ctetools/CodeStore/3566/webrev/src/share/classes/java/util/zip/GZIPInputStream.java.sdiff.html 7 diff: http://cr.openjdk.java.net/~sherman/4691425/webrev/src/share/classes/java/util/zip/GZIPInputStream.java.sdiff.html
12-01-2011