You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2013/01/19 15:02:01 UTC

svn commit: r1435549 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/zip/ZipFile.java

Author: bodewig
Date: Sat Jan 19 14:02:01 2013
New Revision: 1435549

URL: http://svn.apache.org/viewvc?rev=1435549&view=rev
Log:
COMPRESS-215 improve central directory location for Zip32 archives, based on patch by Robin Power

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1435549&r1=1435548&r2=1435549&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Sat Jan 19 14:02:01 2013
@@ -124,8 +124,14 @@ The <action> type attribute can be add,u
                 due-to="Julius Davies">
             ZipShort, ZipLong, ZipEightByteInteger should implement Serializable
         </action>
-        <action type="update" date="2013-01-14" issue="COMPRESS-214" due-to="Julius Davies">
-            better support for unix symlinks
+        <action type="update" date="2013-01-14" issue="COMPRESS-214"
+                due-to="Julius Davies">
+            better support for unix symlinks in ZipFile entries
+        </action>
+        <action type="update" date="2013-01-19" issue="COMPRESS-215"
+                due-to="Robin Power">
+          ZipFile's initialization has been improved for non-Zip64
+          archives.
         </action>
     </release>
     <release version="1.4.1" date="2012-05-23"

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java?rev=1435549&r1=1435548&r2=1435549&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java Sat Jan 19 14:02:01 2013
@@ -666,12 +666,14 @@ public class ZipFile {
      */
     private void positionAtCentralDirectory()
         throws IOException {
-        boolean found = tryToLocateSignature(MIN_EOCD_SIZE + ZIP64_EOCDL_LENGTH,
-                                             MAX_EOCD_SIZE + ZIP64_EOCDL_LENGTH,
-                                             ZipArchiveOutputStream
-                                             .ZIP64_EOCD_LOC_SIG);
+        positionAtEndOfCentralDirectoryRecord();
+        archive.seek(archive.getFilePointer() - ZIP64_EOCDL_LENGTH);
+        archive.readFully(WORD_BUF);
+        boolean found = Arrays.equals(ZipArchiveOutputStream.ZIP64_EOCD_LOC_SIG,
+                                      WORD_BUF);
         if (!found) {
             // not a ZIP64 archive
+            skipBytes(ZIP64_EOCDL_LENGTH - WORD);
             positionAtCentralDirectory32();
         } else {
             positionAtCentralDirectory64();
@@ -686,7 +688,8 @@ public class ZipFile {
      */
     private void positionAtCentralDirectory64()
         throws IOException {
-        skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET);
+        skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET
+                  - WORD /* signature has already been read */);
         archive.readFully(DWORD_BUF);
         archive.seek(ZipEightByteInteger.getLongValue(DWORD_BUF));
         archive.readFully(WORD_BUF);
@@ -707,14 +710,22 @@ public class ZipFile {
      */
     private void positionAtCentralDirectory32()
         throws IOException {
+        skipBytes(CFD_LOCATOR_OFFSET);
+        archive.readFully(WORD_BUF);
+        archive.seek(ZipLong.getValue(WORD_BUF));
+    }
+
+    /**
+     * Searches for the and positions the stream at the start of the
+     * &quot;End of central dir record&quot;.
+     */
+    private void positionAtEndOfCentralDirectoryRecord()
+        throws IOException {
         boolean found = tryToLocateSignature(MIN_EOCD_SIZE, MAX_EOCD_SIZE,
                                              ZipArchiveOutputStream.EOCD_SIG);
         if (!found) {
             throw new ZipException("archive is not a ZIP archive");
         }
-        skipBytes(CFD_LOCATOR_OFFSET);
-        archive.readFully(WORD_BUF);
-        archive.seek(ZipLong.getValue(WORD_BUF));
     }
 
     /**