You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2009/03/30 02:39:05 UTC
svn commit: r759807 -
/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Author: sebb
Date: Mon Mar 30 00:39:05 2009
New Revision: 759807
URL: http://svn.apache.org/viewvc?rev=759807&view=rev
Log:
Empty Zip files start with End of Central directory
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=759807&r1=759806&r2=759807&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java Mon Mar 30 00:39:05 2009
@@ -266,18 +266,26 @@
throw new IllegalArgumentException();
}
+ /*
+ * This test assumes that the zip file does not have any additional leading content,
+ * which is something that is allowed by the specification (e.g. self-extracting zips)
+ */
public static boolean matches(byte[] signature, int length) {
if (length < ZipArchiveOutputStream.LFH_SIG.length) {
return false;
}
- for (int i = 0; i < ZipArchiveOutputStream.LFH_SIG.length; i++) {
- if (signature[i] != ZipArchiveOutputStream.LFH_SIG[i]) {
+ return checksig(signature, ZipArchiveOutputStream.LFH_SIG) // normal file
+ || checksig(signature, ZipArchiveOutputStream.EOCD_SIG); // empty zip
+ }
+
+ private static boolean checksig(byte[] signature, byte[] expected){
+ for (int i = 0; i < expected.length; i++) {
+ if (signature[i] != expected[i]) {
return false;
}
}
-
- return true;
+ return true;
}
private void closeEntry() throws IOException {