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

ZipFileSystem throws unexpected end of ZLIB input stream when copying zip file

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 8
    • core-libs
    • None

      Unit test:
      public class ZipCloneTest {
          public static void main(String[] args) throws IOException {
              Map<String, Object> env = new HashMap<>();
      env.put("encoding", "utf-8");
              env.put("create", "true");

              // create a source zip file abc.jar
              Path file = Paths.get("abc.jar");
              java.nio.file.Files.deleteIfExists(file);
              URI uri = URI.create("jar:" + file.toUri().toString());
              ZipFileSystem fs = (ZipFileSystem) FileSystems.newFileSystem(uri, env, null);
              Path p = fs.getPath("/");
              java.nio.file.Files.createFile(p.resolve("1.txt"));
              fs.close();
              
              Map<String, Object> env2 = new HashMap<>();
              env2.put("encoding", "utf-8");
              ZipFileSystem fs2 = (ZipFileSystem) FileSystems.newFileSystem(uri, env2, null);
              Path p2 = fs2.getPath("/1.txt");
              
              // copy files of abc.jar into def.jar
              Path file3 = Paths.get("def.jar");
              java.nio.file.Files.deleteIfExists(file3);
              URI uri3 = URI.create("jar:" + file3.toUri().toString());
              ZipFileSystem fs3 = (ZipFileSystem)FileSystems.newFileSystem(uri3, env, null);
              Path p3 = fs3.getPath("/").resolve("3.txt");
              java.nio.file.Files.copy(p2, p3);
              fs3.close();
              fs2.close();
          }
      }

      Expected:
      test passed without exception

      Actual:
      Exception in thread "main" java.io.EOFException: Unexpected end of ZLIB input stream
      at com.sun.nio.zipfs.ZipFileSystem$5.fill(ZipFileSystem.java:1427)
      at java.util.zip.InflaterInputStream.read(InflaterInputStream.java:158)
      at java.io.FilterInputStream.read(FilterInputStream.java:107)
      at com.sun.nio.zipfs.ZipPath.copyToTarget(ZipPath.java:858)
      at com.sun.nio.zipfs.ZipPath.copy(ZipPath.java:817)
      at com.sun.nio.zipfs.ZipFileSystemProvider.copy(ZipFileSystemProvider.java:194)
      at java.nio.file.Files.copy(Files.java:1234)
      at ZipCloneTest.main(ZipCloneTest.java:34)
      Java Result: 1

            sherman Xueming Shen
            ewang Eric Wang (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: