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

ZipInputStream reads too much data per entry and throws ZipException

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 Pro N 64bit
      JDK 1.8.0 131, 152, 161
      JDK 10.0.2
      JDK 11.0.1
      JDK 12 EA 17

      A DESCRIPTION OF THE PROBLEM :
      I have a set of Zip Files coming from a 3rd party software which fail to be read via the ZipInputStream. I do not know what zip library is used by this software but they there is zlib in place which is likely used for compression algorithms. It apprears that too much data is read per ZipEntry which ultimately leads to a ZipException reading:

      Exception in thread "main" java.util.zip.ZipException: invalid entry size (expected 5159 but got 19702 bytes)

      The same files can be extracted in many other tools and frameworks:
      - Windows Explorer
      - 7zip 18.05
      - WinRar 5.50
      - .net System.IO.Compression.ZipArchive class (.net 4.7.1)
      - Haxe Zip Reader (https://github.com/HaxeFoundation/haxe/tree/development/std/haxe/zip)

      I tested many available SDKs and with none it is working:
      - 1.8.0
      - 10.0.2
      - 11.0.1
      - 12 EA 17


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the provided source code to unzip the provided test files. Files will be provided separately (bug report form does not support file uploads).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Extraction works as expected without exception.
      ACTUAL -

      Exception in thread "main" java.util.zip.ZipException: invalid entry size (expected 5159 but got 19702 bytes)
      at java.base/java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:398)
      at java.base/java.util.zip.ZipInputStream.read(ZipInputStream.java:197)
      at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107)
      at Test.main(Test.java:20)

      ---------- BEGIN SOURCE ----------
      import java.io.ByteArrayOutputStream;
      import java.io.FileInputStream;
      import java.util.zip.ZipEntry;
      import java.util.zip.ZipInputStream;

      public class Test {
          public static void main(String[] args) throws Exception {
              FileInputStream input = new FileInputStream(args[0]);
              ZipInputStream zip = new ZipInputStream(input);
              try {
                  byte[] buffer = new byte[2048];
                  ZipEntry entry;
                  while ((entry = zip.getNextEntry()) != null) {
                      ByteArrayOutputStream data = new ByteArrayOutputStream();
                      int len = 0;
                      while ((len = zip.read(buffer)) > 0) {
                          data.write(buffer, 0, len);
                      }
                      System.out.println("Entry: " + entry.getName() + ", Size:" + data.toByteArray().length);
                  }
              } finally {
                  input.close();
              }
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

        1. JDK8213191.java
          0.8 kB
        2. Test01.zip
          10 kB
        3. Test02.zip
          9 kB
        4. Test03.zip
          9 kB

          Activity

            People

            • Assignee:
              lancea Lance Andersen
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: