commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1153735 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Date Thu, 04 Aug 2011 02:58:47 GMT
Author: bodewig
Date: Thu Aug  4 02:58:46 2011
New Revision: 1153735

URL: http://svn.apache.org/viewvc?rev=1153735&view=rev
Log:
the loop searching for the signature could be reading beyond the start of the archive

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

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=1153735&r1=1153734&r2=1153735&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
Thu Aug  4 02:58:46 2011
@@ -542,11 +542,15 @@ public class ZipFile {
                                          byte[] sig) throws IOException {
         boolean found = false;
         long off = archive.length() - minDistanceFromEnd;
-        long stopSearching = Math.max(0L, archive.length() - maxDistanceFromEnd);
+        final long stopSearching =
+            Math.max(0L, archive.length() - maxDistanceFromEnd);
         if (off >= 0) {
-            archive.seek(off);
-            int curr = archive.read();
-            while (off >= stopSearching && curr != -1) {
+            for (; off >= stopSearching; off--) {
+                archive.seek(off);
+                int curr = archive.read();
+                if (curr == -1) {
+                    break;
+                }
                 if (curr == sig[POS_0]) {
                     curr = archive.read();
                     if (curr == sig[POS_1]) {
@@ -560,8 +564,6 @@ public class ZipFile {
                         }
                     }
                 }
-                archive.seek(--off);
-                curr = archive.read();
             }
         }
         if (found) {



Mime
View raw message