I have a small program that reads entries from a zip (jar) file, and writes them
out to another zip file.
When I use our nightly build, I get an error "expected 0xffffffff8bcdbdcc but got 0x8bcdbdcc":
laguna{luehe}115: /usr/security/nightly/ws/solaris/JDK1.2bugs/build/solaris/bin/java ZipTest x509.jar out.jar
META-INF/MANIFEST.MF: method= 8, CRC=-1949450804
META-INF/TTT.SF: method= 8, CRC=-450279610
java.util.zip.ZipException: invalid entry CRC-32 (expected 0xffffffff8bcdbdcc but got 0x8bcdbdcc)
at java.util.zip.ZipOutputStream.closeEntry(ZipOutputStream.java:195)
at java.util.zip.ZipOutputStream.putNextEntry(ZipOutputStream.java:113)
at ZipTest.writeEntry(ZipTest.java:75)
at ZipTest.run(ZipTest.java:51)
at ZipTest.main(ZipTest.java:19)
However, when I use the "JDK-1.2beta3-K" build, everything seems to work fine.
laguna{luehe}116: /usr/local/java/jdk1.2/solaris/bin/java ZipTest x509.jar out.jar
x509/PKIXExtensions.class: method= 8, CRC=1944216257
x509/Extension.class: method= 8, CRC=1078045011
x509/RDN.class: method= 8, CRC=3033619565
x509/DNSName.class: method= 8, CRC=335038015
x509/BasicConstraintsExtension.class: method= 8, CRC=2726800908
x509/ReasonFlags.class: method= 8, CRC=3264635430
x509/EDIPartyName.class: method= 8, CRC=3811599804
META-INF/TTT.DSA: method= 8, CRC=1197588713
x509/NameConstraintsExtension.class: method= 8, CRC=2567528146
x509/RevokedCertImpl.class: method= 8, CRC=1341248530
x509/: method= 0, CRC=0
x509/cacerts/: method= 0, CRC=0
META-INF/TTT.SF: method= 8, CRC=3844687686
META-INF/MANIFEST.MF: method= 8, CRC=2345516492
x509/cacerts/Verisign.class: method= 8, CRC=2309307208
x509/RFC822Name.class: method= 8, CRC=3372306682
x509/PrivateKeyUsageExtension.class: method= 8, CRC=214863645
import java.util.*;
import java.util.zip.*;
import java.io.*;
public class ZipTest {
ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
byte[] buffer = new byte[8192];
public static void main(String[] args) {
if (args.length != 2) {
System.err.println("usage: java ZipTest <in> <out>");
System.exit(1);
}
try {
ZipTest zt = new ZipTest();
zt.run(args);
} catch (Exception e) {
e.printStackTrace();
}
}
void run(String[] args) throws Exception {
// Open the jar (zip) file
ZipFile zipFile = null;
try {
zipFile = new ZipFile(args[0]);
} catch (IOException ioe) {
System.err.println("unable to open jar file: "+args[0]);
}
// create ZipOutputStream
FileOutputStream fos = null;
try {
fos = new FileOutputStream(args[1]);
} catch (IOException ioe) {
System.out.println("unable to create: "+args[1]);
}
PrintStream ps = new PrintStream(fos);
ZipOutputStream zos = new ZipOutputStream(ps);
// read each entry, and write it out
for (Enumeration enum=zipFile.entries(); enum.hasMoreElements();) {
ZipEntry ze = (ZipEntry)enum.nextElement();
System.out.println(ze.getName()+": method= "+ze.getMethod()
+", CRC="+ze.getCrc());
// write entries out
writeEntry(zipFile, zos, ze);
}
}
/*
* Reads all the bytes for a given zip entry.
*/
synchronized byte[] getBytes(ZipFile zf,
ZipEntry ze) throws IOException {
int n;
InputStream is = zf.getInputStream(ze);
baos.reset();
long left = ze.getSize();
while((left > 0) && (n = is.read(buffer, 0, buffer.length)) != -1) {
baos.write(buffer, 0, n);
left -= n;
}
is.close();
return baos.toByteArray();
}
void writeEntry(ZipFile zf, ZipOutputStream os, ZipEntry ze)
throws IOException {
byte[] data = getBytes(zf, ze);
os.putNextEntry(ze);
if (data.length > 0) {
os.write(data);
}
}
}