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

Catch unexpected end of ZLIB while reading from InputStream for some ZIP files.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.2.0
    • 2.0, 1.1, 1.1.2, 1.2.0
    • tools
    • None
    • jar
    • 1.2beta4
    • generic, x86, sparc
    • generic, solaris_9, windows_95
    • Verified

      Exception only occurs for certain files in a ZIP file.
      I found this out while decompressing the latest Java Tutorial (ZIP version).
      While decompressing it, 4 files throws exception:

      ui/drawing/images/MovingImage.gif
      images/HJLogo/T12.gif
      java/threads/example/RaceTest.class
      java/threads/example/BidirectionalBubbleSortAlgorithm.class

      Even though the exception is thrown, I found out that the 4 files are OK. There
      seem to be no corruption at all since I compared this with the files that was
      decompressed using the "unzip" program from /usr/dist.
      One of the file "MovingImage.gif" is compress in ZIP format in the attachment
      "a.zip".

      To reproduce this bug, get "a.zip" from attachment, compile the code below and
      type "java unzip a.zip".

      Error message for this bug is:

      While reading: java.io.EOFException: Unexpected end of ZLIB input stream
      java.io.EOFException: Unexpected end of ZLIB input stream
              at java.lang.Throwable.<init>(Compiled Code)
              at java.lang.Exception.<init>(Compiled Code)
              at java.io.IOException.<init>(Compiled Code)
              at java.io.EOFException.<init>(Compiled Code)
              at java.util.zip.InflaterInputStream.fill(Compiled Code)
              at java.util.zip.InflaterInputStream.read(Compiled Code)
              at java.io.FilterInputStream.read(Compiled Code)
              at unzip.main(Compiled Code)


      ==============
      Source code is:

      import java.lang.*;
      import java.io.*;
      import java.util.*;
      import java.util.zip.*;

      class unzip{
          public static void main(String[] args){
              if ( args.length < 1 ){
                  System.out.println("Usage: java unzip <filename>");
                  System.exit(1);
              }

              String filename=args[0];

              try{
                  ZipFile fis = new ZipFile(filename);
                  String line;
                  byte buffer[] = new byte[1024];
                  int length;

                  System.out.println();

                  //--- Creating files ---//
                  for(Enumeration e=fis.entries(); e.hasMoreElements();){
                      Object o=e.nextElement();
                      line=o.toString();

                      ZipEntry zentry=fis.getEntry(line);

                      System.out.println("Inflating "+line+"...");
                      InputStream inflate=fis.getInputStream(zentry);
                      RandomAccessFile outfile=new RandomAccessFile(line,"rw");

                      //-- Sometimes ZLIB unexpected EOF error occur.--//
                      //-- We don't want to exit because of it. --//
                      try{
                          while ( (length=inflate.read(buffer)) != -1){
                          outfile.write(buffer,0,length);
                          }
                      } catch(IOException ex){
                          System.out.println("While reading: " + ex);
                          ex.printStackTrace();
                      }

                      outfile.close();
                  }

                  fis.close();
              } catch(FileNotFoundException e){
                  System.err.println("Decompress: " + e);
              } catch(IOException e){
                  System.err.println("Decompress: " + e);
              }
          }
      }
      =================================================================

      This problem occurs 100% repeatably on two zip files that
      I have, but some other files work okay. I will send problem zip
      files at your request. The files were created by ZipIt on
      the Mac, and can be deflated okay by unzip (PD version) on Win95
      and by WinZip on Win95.

      The output, including the stack trace, is:

      +++ zip = java.util.zip.ZipFile@1cc748
      +++ zip file entry 1 = ICONS/grain22.ico
      +++ 7358 characters
      +++ zip file entry 2 = ICONS/grain12.ico
      +++ 7358 characters
      +++ zip file entry 3 = ICONS/grain02.ico
      java.io.EOFException: Unexpected end of ZLIB input stream
              at java.util.zip.InflaterInputStream.fill(InflaterInputStream.java:156)
              at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:119)
              at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:94)
              at JZip.main(JZip.java:20)


      Here is the source program, which simply accesses every byte of
      every entry in a zip file:

      --------- JZip.java ---------------------------
      import java.util.zip.*;
      import java.util.*;
      import java.io.*;

      class JZip {

          public static void main(String[] args) {
      try {
      ZipFile zip = new ZipFile(args[0]);
      System.out.println("+++ zip = " + zip);
      Enumeration entries = zip.entries();
      int n = 0;
      while (entries.hasMoreElements()) {
      ZipEntry entry = (ZipEntry)entries.nextElement();
      ++n;
      System.out.println("+++ zip file entry " + n + " = " + entry);
      InputStream input = zip.getInputStream(entry);
      int c;
      int count = 0;
      while ((c = input.read()) >= 0)
      ++count; // System.out.print((char)c);
      System.out.println("+++ " + count + " characters");
      }
      } catch (Exception e) {
      e.printStackTrace();
      }
          }

      }
      -----------------------------
      company - Radius , email - ###@###.###

            dconnellsunw David Connelly (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: