-
Bug
-
Resolution: Fixed
-
P4
-
1.1.7, 1.4.0, 1.4.2, 5.0
-
tiger
-
generic, x86
-
generic, windows_2000, windows_xp
Name: dbT83986 Date: 08/15/99
Uncompressing a file using java.util.zip.GZIPInputStream fails if the uncompressed file is 2GB or larger (it works for files up to 2,147,483,647 bytes). I suspect that the problem is an overflow, presumably of a variable somewhere in GZIPInputStream that should be declared as long, but is declared as int.
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
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)
(Review ID: 93899)
======================================================================
Uncompressing a file using java.util.zip.GZIPInputStream fails if the uncompressed file is 2GB or larger (it works for files up to 2,147,483,647 bytes). I suspect that the problem is an overflow, presumably of a variable somewhere in GZIPInputStream that should be declared as long, but is declared as int.
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
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)
(Review ID: 93899)
======================================================================
- relates to
-
JDK-5092263 GZIPInputStream spuriously reports "Corrupt GZIP trailer" for sizes > 2GB
- Resolved
-
JDK-4418997 Files between 2 Gb and 4Gb (excluded) are not accepted in a zip file.
- Resolved
-
JDK-4795136 CRC check fails for files over 2 GB
- Resolved
-
JDK-6419239 jar can add files to an archive that it can't later extract
- Resolved
-
JDK-6599383 Unable to open zip files more than 2GB in size
- Resolved
-
JDK-6373678 GZIPInputStream throws Corrupt GZIP Trailer on large files in 1.5.0
- Closed
(1 relates to)