Other |
---|
5.0 tigerFixed |
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
|
Relates :
|
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) ======================================================================
|