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

Zip output has wrong extra field length in directory header

    XMLWordPrintable

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Linux, Java 11.0.1.

      A DESCRIPTION OF THE PROBLEM :
      When creation time is set on a ZipEntry, output results in a directory header with a bad "extra field" length. new ZipFile will fail when it verifies the directory; tools such as zipinfo or unzip -v also fail.

      REGRESSION : Last worked in version 8u192

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      $ java -version
      openjdk version "11.0.1" 2018-10-16
      OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
      OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
      $ javac zippy/Test.java && java zippy.Test
      java.util.zip.ZipException: invalid CEN header (bad header size)
      at java.base/java.util.zip.ZipFile$Source.zerror(ZipFile.java:1529)
      at java.base/java.util.zip.ZipFile$Source.initCEN(ZipFile.java:1524)
      at java.base/java.util.zip.ZipFile$Source.<init>(ZipFile.java:1268)
      at java.base/java.util.zip.ZipFile$Source.get(ZipFile.java:1231)
      at java.base/java.util.zip.ZipFile$CleanableResource.<init>(ZipFile.java:726)
      at java.base/java.util.zip.ZipFile$CleanableResource.get(ZipFile.java:843)
      at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:246)
      at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:176)
      at java.base/java.util.zip.ZipFile.<init>(ZipFile.java:190)
      at zippy.Test.unsafe(Test.java:37)
      at zippy.Test.run(Test.java:17)
      at zippy.Test.main(Test.java:43)


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      $ java -version
      openjdk version "1.8.0_192"
      OpenJDK Runtime Environment (Zulu 8.33.0.1-linux64) (build 1.8.0_192-b01)
      OpenJDK 64-Bit Server VM (Zulu 8.33.0.1-linux64) (build 25.192-b01, mixed mode)
      $ javac zippy/Test.java && java zippy.Test
      $ hexdump -C out.zip
      00000000 50 4b 03 04 14 00 08 08 08 00 57 82 2e 4e 00 00 |PK........W..N..|
      00000010 00 00 00 00 00 00 00 00 00 00 06 00 00 00 4d 59 |..............MY|
      00000020 4c 49 53 54 cb ad cc c9 2c 2e d1 4d aa 2c 49 2d |LIST....,..M.,I-|
      00000030 06 00 50 4b 07 08 8e d4 2d 85 0e 00 00 00 0c 00 |..PK....-.......|
      00000040 00 00 50 4b 03 04 14 00 08 08 08 00 57 82 2e 4e |..PK........W..N|
      00000050 00 00 00 00 00 00 00 00 00 00 00 00 06 00 09 00 |................|
      00000060 4d 59 46 49 4c 45 55 54 05 00 04 e7 26 3d 5c cb |MYFILEUT....&=\.|
      00000070 ad 4c cb cc 49 d5 4d aa 2c 49 2d 06 00 50 4b 07 |.L..I.M.,I-..PK.|
      00000080 08 ba f0 3d f6 0e 00 00 00 0c 00 00 00 50 4b 01 |...=.........PK.|
      00000090 02 14 00 14 00 08 08 08 00 57 82 2e 4e 8e d4 2d |.........W..N..-|
      000000a0 85 0e 00 00 00 0c 00 00 00 06 00 00 00 00 00 00 |................|
      000000b0 00 00 00 00 00 00 00 00 00 00 00 4d 59 4c 49 53 |...........MYLIS|
      000000c0 54 50 4b 01 02 14 00 14 00 08 08 08 00 57 82 2e |TPK..........W..|
      000000d0 4e ba f0 3d f6 0e 00 00 00 0c 00 00 00 06 00 05 |N..=............|
      000000e0 00 00 00 00 00 00 00 00 00 00 00 42 00 00 00 4d |...........B...M|
      000000f0 59 46 49 4c 45 55 54 01 00 04 50 4b 05 06 00 00 |YFILEUT...PK....|
      00000100 00 00 02 00 02 00 6d 00 00 00 8d 00 00 00 00 00 |......m.........|

      ACTUAL -
      # 9 at df should be 5
      $ hexdump -C out.zip
      00000000 50 4b 03 04 14 00 08 08 08 00 1a 82 2e 4e 00 00 |PK...........N..|
      00000010 00 00 00 00 00 00 00 00 00 00 06 00 00 00 4d 59 |..............MY|
      00000020 4c 49 53 54 cb ad cc c9 2c 2e d1 4d aa 2c 49 2d |LIST....,..M.,I-|
      00000030 06 00 50 4b 07 08 8e d4 2d 85 0e 00 00 00 0c 00 |..PK....-.......|
      00000040 00 00 50 4b 03 04 14 00 08 08 08 00 1a 82 2e 4e |..PK...........N|
      00000050 00 00 00 00 00 00 00 00 00 00 00 00 06 00 09 00 |................|
      00000060 4d 59 46 49 4c 45 55 54 05 00 04 75 26 3d 5c cb |MYFILEUT...u&=\.|
      00000070 ad 4c cb cc 49 d5 4d aa 2c 49 2d 06 00 50 4b 07 |.L..I.M.,I-..PK.|
      00000080 08 ba f0 3d f6 0e 00 00 00 0c 00 00 00 50 4b 01 |...=.........PK.|
      00000090 02 14 00 14 00 08 08 08 00 1a 82 2e 4e 8e d4 2d |............N..-|
      000000a0 85 0e 00 00 00 0c 00 00 00 06 00 00 00 00 00 00 |................|
      000000b0 00 00 00 00 00 00 00 00 00 00 00 4d 59 4c 49 53 |...........MYLIS|
      000000c0 54 50 4b 01 02 14 00 14 00 08 08 08 00 1a 82 2e |TPK.............|
      000000d0 4e ba f0 3d f6 0e 00 00 00 0c 00 00 00 06 00 09 |N..=............|
      000000e0 00 00 00 00 00 00 00 00 00 00 00 42 00 00 00 4d |...........B...M|
      000000f0 59 46 49 4c 45 55 54 01 00 04 50 4b 05 06 00 00 |YFILEUT...PK....|
      00000100 00 00 02 00 02 00 6d 00 00 00 8d 00 00 00 00 00 |......m.........|


      ---------- BEGIN SOURCE ----------
      package zippy;

      import java.util.zip.ZipEntry;
      import java.util.zip.ZipFile;
      import java.util.zip.ZipOutputStream;
      import java.io.IOException;
      import java.io.OutputStream;
      import java.nio.charset.StandardCharsets;
      import java.nio.file.*;
      import java.nio.file.attribute.FileTime;
      import java.time.Instant;

      public class Test {

        public void run() {
          try {
            unsafe();
          } catch (IOException e) {
            e.printStackTrace();
          }
        }

        public void unsafe() throws IOException {
          Path out = Paths.get("out.zip");
          OutputStream outs = Files.newOutputStream(out);
          try (ZipOutputStream zos = new ZipOutputStream(outs)) {
            ZipEntry entry = new ZipEntry("MYLIST");
            zos.putNextEntry(entry);
            zos.write("mylist-bytes".getBytes(StandardCharsets.UTF_8));

            entry = new ZipEntry("MYFILE");
            entry.setCreationTime(FileTime.from(Instant.now()));
            zos.putNextEntry(entry);
            zos.write("myfile-bytes".getBytes(StandardCharsets.UTF_8));
          }

          ZipFile zipped = new ZipFile(out.toFile());
          zipped.close();
        }

        public static void main(String[] args) {
          Test test = new Test();
          test.run();
        }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: