javac doesn't work with jar files with >64k entries
Martin Buchholz
martinrb at google.com
Fri Nov 16 15:35:46 PST 2012
I'll provide you with version 0.1 of the fix to get you started.
The idea is:
- nuke entryCount
- remove the entryCount "field" from zipDir
- replace entryCount test with simply running off the end of the zipDir
array
Completely untested. I leave the rest to you.
diff --git a/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java
b/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java
--- a/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java
+++ b/src/share/classes/com/sun/tools/javac/file/ZipFileIndex.java
@@ -548,17 +548,17 @@
}
if (i >= 0) {
- zipDir = new byte[get4ByteLittleEndian(endbuf, i + 12)
+ 2];
- zipDir[0] = endbuf[i + 10];
- zipDir[1] = endbuf[i + 11];
+ zipDir = new byte[get4ByteLittleEndian(endbuf, i +
12)];
+// zipDir[0] = endbuf[i + 10];
+// zipDir[1] = endbuf[i + 11];
int sz = get4ByteLittleEndian(endbuf, i + 16);
// a negative offset or the entries field indicates a
// potential zip64 archive
- if (sz < 0 || get2ByteLittleEndian(zipDir, 0) ==
0xffff) {
+ if (sz < 0 || get2ByteLittleEndian(endbuf, i + 10) ==
0xffff) {
throw new ZipFormatException("detected a zip64
archive");
}
zipRandomFile.seek(start + sz);
- zipRandomFile.readFully(zipDir, 2, zipDir.length - 2);
+ zipRandomFile.readFully(zipDir, 0, zipDir.length);
return;
} else {
endbufend = endbufpos + 21;
@@ -568,14 +568,14 @@
}
private void buildIndex() throws IOException {
- int entryCount = get2ByteLittleEndian(zipDir, 0);
+ // int entryCount = get2ByteLittleEndian(zipDir, 0);
+ int len = zipDir.length;
// Add each of the files
- if (entryCount > 0) {
+ if (len > 0) {
directories = new LinkedHashMap<RelativeDirectory,
DirectoryEntry>();
ArrayList<Entry> entryList = new ArrayList<Entry>();
- int pos = 2;
- for (int i = 0; i < entryCount; i++) {
+ for (int pos = 0; pos < len; ) {
pos = readEntry(pos, entryList, directories);
}
On Fri, Nov 16, 2012 at 3:10 PM, Jonathan Gibbons <
jonathan.gibbons at oracle.com> wrote:
> Thanks, we'll look to get it fixed.
>
> -- Jon
>
>
> On 11/16/2012 03:09 PM, Martin Buchholz wrote:
>
> Here is a repro recipe:
>
> $ for x in *.java bug-demo; do echo --- $x ---; cat $x; done; echo ===;
> ./bug-demo $JDK6 $JDK8
> --- A.java ---
> public class A {}
> --- Main.java ---
> public class Main {
> public static void main(String[] args) {
> System.out.println(new A());
> }
> }
> --- MakeJar.java ---
> /*
> * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
> * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
> *
> * This code is free software; you can redistribute it and/or modify it
> * under the terms of the GNU General Public License version 2 only, as
> * published by the Free Software Foundation.
> *
> * This code is distributed in the hope that it will be useful, but WITHOUT
> * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
> * version 2 for more details (a copy is included in the LICENSE file that
> * accompanied this code).
> *
> * You should have received a copy of the GNU General Public License
> version
> * 2 along with this work; if not, write to the Free Software Foundation,
> * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
> *
> * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
> * or visit www.oracle.com if you need additional information or have any
> * questions.
> */
>
> import java.io.*;
> import java.util.*;
> import java.util.zip.*;
>
> public class MakeJar {
> public static void main(String[] args) throws Throwable {
> File classFile = new File("A.class");
> ZipOutputStream zos = null;
> FileInputStream fis = null;
> final int MAX = Short.MAX_VALUE * 2 + 10;
> ZipEntry ze = null;
> try {
> zos = new ZipOutputStream(new FileOutputStream("a.jar"));
> zos.setLevel(ZipOutputStream.STORED);
> zos.setMethod(ZipOutputStream.STORED);
> for (int i = 0; i < MAX ; i++) {
> ze = new ZipEntry("X" + i + ".txt");
> ze.setSize(0);
> ze.setCompressedSize(0);
> ze.setCrc(0);
> zos.putNextEntry(ze);
> }
>
> // add a class file
> ze = new ZipEntry("A.class");
> ze.setCompressedSize(classFile.length());
> ze.setSize(classFile.length());
> ze.setCrc(computeCRC(classFile));
> zos.putNextEntry(ze);
> fis = new FileInputStream(classFile);
> for (int c; (c = fis.read()) >= 0;)
> zos.write(c);
> } finally {
> zos.close();
> fis.close();
> }
> }
>
> private static final long GIGA = 1024 * 1024 * 1024;
> private static final int BUFFER_LEN = Short.MAX_VALUE * 2;
>
> static long getCount(long minlength) {
> return (minlength / BUFFER_LEN) + 1;
> }
>
> static long computeCRC(long minlength) {
> CRC32 crc = new CRC32();
> byte[] buffer = new byte[BUFFER_LEN];
> long count = getCount(minlength);
> for (long i = 0; i < count; i++) {
> crc.update(buffer);
> }
> return crc.getValue();
> }
>
> static long computeCRC(File inFile) throws IOException {
> byte[] buffer = new byte[8192];
> CRC32 crc = new CRC32();
> FileInputStream fis = null;
> BufferedInputStream bis = null;
> try {
> fis = new FileInputStream(inFile);
> bis = new BufferedInputStream(fis);
> int n = bis.read(buffer);
> while (n > 0) {
> crc.update(buffer, 0, n);
> n = bis.read(buffer);
> }
> } finally {
> bis.close();
> fis.close();
> }
> return crc.getValue();
> }
> }
> --- bug-demo ---
> #!/bin/bash
> JDK6="$1" JDK8="$2"
> set -eu
> $JDK6/bin/java -fullversion
> $JDK8/bin/java -fullversion
> echo ----
> $JDK6/bin/javac A.java Main.java MakeJar.java
> $JDK6/bin/java MakeJar
> $JDK6/bin/jar tf a.jar A.class
> echo ----
> $JDK8/bin/javac -sourcepath / -classpath a.jar Main.java
> ===
> java full version "1.6.0_38-ea-b03"
> java full version "1.8.0-ea-b62"
> ----
> A.class
> ----
> Main.java:3: error: cannot find symbol
> System.out.println(new A());
> ^
> symbol: class A
> location: class Main
> 1 error
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20121116/456cce6a/attachment.html
More information about the compiler-dev
mailing list