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

zip files with total entry count 0xFFFF need not be ZIP64 files

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 9
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Introduced In Version:
      8
    • Resolved In Build:
      b59
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        If a zip implementation writes a zip file with exactly 0xFFFF entries, then it is within its rights to write a non-ZIP64 zip file. But some JDK code assumes that the presence of 0xFFFF in the zip end of central directory header indicates the presence of a ZIP64 header, failing when one cannot be found. This is a regression.

        SSCCE:

         (set -x; cat FFFF.java; cat Main.java; ~/jdk/jdk6/bin/javac Main.java FFFF.java && ~/jdk/jdk6/bin/java FFFF && for x in 6 7 8 9; do ~/jdk/jdk$x/bin/java -jar ffff.zip ; done)
        +/bin/zsh:19> cat FFFF.java
        import java.io.*;
        import java.util.*;
        import java.util.zip.*;
        import java.util.jar.*;

        public class FFFF {
            public static void main(String[] args) throws Throwable {
                File f = new File("ffff.zip");
                OutputStream os = new FileOutputStream(f);
                ZipOutputStream s = new ZipOutputStream(os);

                ZipEntry man = new ZipEntry("META-INF/MANIFEST.MF");
                s.putNextEntry(man);
                s.write("Manifest-Version: 1.0\n".getBytes("US-ASCII"));
                s.write("Main-Class: Main\n".getBytes("US-ASCII"));
                s.closeEntry();

                ZipEntry main = new ZipEntry("Main.class");
                s.putNextEntry(main);
                byte buf[] = new byte[10000];
                int n = new FileInputStream("Main.class").read(buf);
                s.write(buf, 0, n);
                s.closeEntry();

                for (int i = 0; i < 0xffff -2; i++) {
                    ZipEntry e = new ZipEntry(String.valueOf(i));
                    s.putNextEntry(e);
                    s.closeEntry();
                }

                s.close();
            }
        }
        +/bin/zsh:19> cat Main.java
        import java.util.*;

        public class Main {
            public static void main(String[] args) {
                System.out.println("Main ffff");
            }
        }
        +/bin/zsh:19> /usr/local/google/home/martinrb/jdk/jdk6/bin/javac Main.java FFFF.java
        +/bin/zsh:19> /usr/local/google/home/martinrb/jdk/jdk6/bin/java FFFF
        +/bin/zsh:19> x=6
        +/bin/zsh:19> /usr/local/google/home/martinrb/jdk/jdk6/bin/java -jar ffff.zip
        Main ffff
        +/bin/zsh:19> x=7
        +/bin/zsh:19> /usr/local/google/home/martinrb/jdk/jdk7/bin/java -jar ffff.zip
        Main ffff
        +/bin/zsh:19> x=8
        +/bin/zsh:19> /usr/local/google/home/martinrb/jdk/jdk8/bin/java -jar ffff.zip
        Error: Invalid or corrupt jarfile ffff.zip
        +/bin/zsh:19> x=9
        +/bin/zsh:19> /usr/local/google/home/martinrb/jdk/jdk9/bin/java -jar ffff.zip
        Error: Invalid or corrupt jarfile ffff.zip

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                martin Martin Buchholz
                Reporter:
                martin Martin Buchholz
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: