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

(zipfs) zip file corruption when replacing an existing STORED entry

    Details

    • Subcomponent:
    • Introduced In Build:
      b18
    • Introduced In Version:
      13
    • Resolved In Build:
      b12

      Backports

        Description

        We started noticing corrupted zip files when we tried updating from jdk11.0.3 to jdk11.0.4 and root caused it to this commit

        changeset: 54608:c604234be658
        user: redestad
        date: 2019-04-24 15:37 +0200
        8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
        Reviewed-by: lancea, clanger, alanb


        Here's a self-documenting repro:

         $ make repro
        set -x; cat Makefile; cat CorruptZip.java; java --version && echo foobar > foo && jar cM0vf foo.zip foo && javac CorruptZip.java && java CorruptZip; unzip -t foo.zip
        + cat Makefile
        # Repro for zip file corruption introduced in
        # 8222532: (zipfs) Performance regression when writing ZipFileSystem entries in parallel
        repro:
        set -x; cat Makefile; cat CorruptZip.java; java --version && echo foobar > foo && jar cM0vf foo.zip foo && javac CorruptZip.java && java CorruptZip; unzip -t foo.zip
        + cat CorruptZip.java
        import java.nio.file.*;

        public class CorruptZip {
            public static void main(String[] args) throws Throwable {
        Path zipPath = Paths.get("foo.zip");
        ClassLoader cl = null;
        try (FileSystem zipfs = FileSystems.newFileSystem(zipPath, cl)) {
        Files.write(zipfs.getPath("foo"),
        "bar".getBytes("ASCII"),
        StandardOpenOption.TRUNCATE_EXISTING,
        StandardOpenOption.CREATE);
        }
        // Test integrity of zip file:
        new java.util.zip.ZipFile("foo.zip");
            }
        }
        + java --version
        openjdk 13-internal 2019-09-17
        OpenJDK Runtime Environment (build 13-internal+0-adhoc.martinrb.zipfs)
        OpenJDK 64-Bit Server VM (build 13-internal+0-adhoc.martinrb.zipfs, mixed mode, sharing)
        + echo foobar
        + jar cM0vf foo.zip foo
        adding: foo(in = 7) (out= 7)(stored 0%)
        + javac CorruptZip.java
        + java CorruptZip
        Exception in thread "main" java.util.zip.ZipException: invalid END header (bad central directory offset)
        at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1470)
        at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1393)
        at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1209)
        at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1172)
        at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:719)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:239)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:169)
        at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:140)
        at CorruptZip.main(CorruptZip.java:14)
        + unzip -t foo.zip
        Archive: foo.zip
        error [foo.zip]: missing 4 bytes in zipfile
          (attempting to process anyway)
        error [foo.zip]: attempt to seek before beginning of zipfile
          (please check that you have transferred or created the zipfile in the
          appropriate BINARY mode and that you have compiled UnZip properly)
          (attempting to re-compensate)
        foo: ucsize 3 <> csize 7 for STORED entry
                 continuing with "compressed" size value
            testing: foo bad CRC 37a79e94 (should be b22c9747)
        At least one error was detected in foo.zip.
        make: *** [Makefile:4: repro] Error 2

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  lancea Lance Andersen
                  Reporter:
                  martin Martin Buchholz
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  16 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: