United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7011162 REGRESSION, incorrect header handling of extra gzip fields
JDK-7011162 : REGRESSION, incorrect header handling of extra gzip fields

Details
Type:
Bug
Submit Date:
2011-01-09
Status:
Closed
Updated Date:
2012-05-31
Project Name:
JDK
Resolved Date:
2011-10-11
Component:
core-libs
OS:
linux,windows_xp,windows_7
Sub-Component:
java.util.jar
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
6u23,6u24
Fixed Versions:
6u30 (b08)

Related Reports
Duplicate:
Duplicate:
Duplicate:

Sub Tasks

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
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
                                     
2011-01-12
SUGGESTED FIX

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



Hardware and Software, Engineered to Work Together