JDK-6373678 : GZIPInputStream throws Corrupt GZIP Trailer on large files in 1.5.0
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util.jar
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-01-18
  • Updated: 2011-02-16
  • Resolved: 2006-01-24
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Windows XP [5.1.2600]

A DESCRIPTION OF THE PROBLEM :
This is a re-submit of bug 4262583, which is wrongly reported as 'fixed' and 'closed'.

When the unzipped contents of a GZIP-compressed file would be more than 2Gigs in size, GZIPInputStream.read() throws an IOException with the message "Corrupt GZIP trailer". Unzipping the file using gunzip works correctly. The bug happens using data compressed by gzip externally, and equivalently by writing the file through a GZIPOutputStream with Java.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See source code for test case below.


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
None - no errors.
ACTUAL -
Exception, shown below.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.IOException: Corrupt GZIP trailer
        at java.util.zip.GZIPInputStream.readTrailer (GZIPInputStream.java:173) (pc 85)
        at java.util.zip.GZIPInputStream.read (GZIPInputStream.java:90) (pc 23)
        at java.util.zip.InflaterInputStream.read                (pc 8)
        at TestGZIP.main      (TestGZIP.java:10)        (pc 24)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Thanks to original reporter.

Here is the program that exhibits the problem:

import java.io.FileInputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

public class TestGZIP {
    public static void main(String[] args) {
        try {
            FileInputStream fis = new FileInputStream(args[0]);
            GZIPInputStream gis = new GZIPInputStream(fis);
            while (gis.read() != -1) {}
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Here is a program for producing a large file (full of zeroes) of a specific length:

import java.io.FileOutputStream;
import java.io.IOException;

public class WriteZeros {
    public static void main(String[] args) throws IOException {
        byte[] buf = new byte[8192];
        long n = Long.parseLong(args[0]);
        FileOutputStream fos = new FileOutputStream(args[1]);
        long m = n / buf.length;
        for (long i = 0; i < m; i++) {
            fos.write(buf, 0, buf.length);
        }
        fos.write(buf, 0, (int)(n % buf.length));
        fos.close();
    }
}

% java WriteZeros 2147483647 twogigminusone
% gzip twogigminusone
% java TestGZIP twogigminusone.gz
% java WriteZeros 2147483648 twogig
% gzip twogig
% java TestGZIP twogig.gz

---------- END SOURCE ----------

Comments
EVALUATION The fix for 5092263 is being backported to 5.0, to be included in an update release.
24-01-2006