test/java/util/zip/GZIP/GZIPInZip.java

Print this page

        

@@ -21,11 +21,12 @@
  * questions.
  */
 
 /* @test
  * @bug 7021870
- * @summary Reading last gzip chain member must not close the input stream
+ * @summary Reading last gzip chain member must not close the input stream.
+ *          Garbage following gzip entry must be ignored.
  */
 
 import java.io.*;
 import java.util.*;
 import java.util.zip.GZIPInputStream;

@@ -38,11 +39,15 @@
 public class GZIPInZip {
 
     private static volatile Throwable trouble;
 
     public static void main(String[] args) throws Throwable {
+        doTest(false);
+        doTest(true);
+    }
 
+    private static void doTest(final boolean appendGarbage) throws Throwable {
         final PipedOutputStream pos = new PipedOutputStream();
         final PipedInputStream pis = new PipedInputStream(pos);
 
         Thread compressor = new Thread() {
             public void run() {

@@ -51,10 +56,13 @@
                     ZipOutputStream zos = new ZipOutputStream(pos);
 
                     zos.putNextEntry(new ZipEntry("a.gz"));
                     GZIPOutputStream gos1 = new GZIPOutputStream(zos);
                     gos1.write(xbuf); gos1.finish();
+                    if (appendGarbage) {
+                        zos.write(xbuf);
+                    }
                     zos.closeEntry();
 
                     zos.putNextEntry(new ZipEntry("b.gz"));
                     GZIPOutputStream gos2 = new GZIPOutputStream(zos);
                     gos2.write(xbuf); gos2.finish();

@@ -69,11 +77,11 @@
         Thread uncompressor = new Thread() {
             public void run() {
                 try {
                     ZipInputStream zis = new ZipInputStream(pis);
                     zis.getNextEntry();
-                    InputStream gis = new GZIPInputStream(zis);
+                    InputStream gis = new GZIPInputStream(zis, 4);
                     // try to read more than the entry has
                     gis.skip(2);
 
                     try {
                         zis.getNextEntry();