Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7011162

REGRESSION, incorrect header handling of extra gzip fields

XMLWordPrintable

    • b08
    • x86
    • linux, windows_xp, windows_7
    • Verified

      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 ----------

            dmeetry Dmeetry Degrave (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: