commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1149029 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Date Thu, 21 Jul 2011 03:49:38 GMT
Author: bodewig
Date: Thu Jul 21 03:49:35 2011
New Revision: 1149029

URL: http://svn.apache.org/viewvc?rev=1149029&view=rev
Log:
deal with entries of a size between Integer.MAX_VALUE and 2 * Integer.MAX_VALUE (size is unsigned
in ZIPs).  COMPRESS-129.  As pointed out by Sebb the solution is incomplete and a more complete
resolution is not possible without requiring Java5.

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=1149029&r1=1149028&r2=1149029&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
Thu Jul 21 03:49:35 2011
@@ -68,8 +68,8 @@ public class ZipArchiveInputStream exten
     private ZipArchiveEntry current = null;
     private boolean closed = false;
     private boolean hitCentralDirectory = false;
-    private int readBytesOfEntry = 0, offsetInBuffer = 0;
-    private int bytesReadFromStream = 0;
+    private int offsetInBuffer = 0;
+    private long readBytesOfEntry = 0, bytesReadFromStream = 0;
     private int lengthOfLastRead = 0;
     private boolean hasDataDescriptor = false;
     private ByteArrayInputStream lastStoredEntry = null;
@@ -256,7 +256,7 @@ public class ZipArchiveInputStream exten
                     return lastStoredEntry.read(buffer, start, length);
                 }
 
-                int csize = (int) current.getSize();
+                long csize = current.getSize();
                 if (readBytesOfEntry >= csize) {
                     return -1;
                 }
@@ -272,7 +272,8 @@ public class ZipArchiveInputStream exten
                     ? lengthOfLastRead - offsetInBuffer
                     : length;
                 if ((csize - readBytesOfEntry) < toRead) {
-                    toRead = csize - readBytesOfEntry;
+                    // if it is smaller than toRead then it fits into an int
+                    toRead = (int) (csize - readBytesOfEntry);
                 }
                 System.arraycopy(buf, offsetInBuffer, buffer, start, toRead);
                 offsetInBuffer += toRead;
@@ -417,16 +418,19 @@ public class ZipArchiveInputStream exten
         } else {
             skip(Long.MAX_VALUE);
 
-            int inB;
+            long inB;
             if (current.getMethod() == ZipArchiveOutputStream.DEFLATED) {
                 inB = inf.getTotalIn();
             } else {
                 inB = readBytesOfEntry;
             }
-            int diff = 0;
+
+            // this is at most a single read() operation and can't
+            // exceed the range of int
+            int diff = (int) (bytesReadFromStream - inB);
 
             // Pushback any required bytes
-            if ((diff = bytesReadFromStream - inB) != 0) {
+            if (diff > 0) {
                 ((PushbackInputStream) in).unread(
                         buf,  lengthOfLastRead - diff, diff);
                 pushedBackBytes(diff);
@@ -438,8 +442,8 @@ public class ZipArchiveInputStream exten
         }
 
         inf.reset();
-        readBytesOfEntry = offsetInBuffer = bytesReadFromStream =
-            lengthOfLastRead = 0;
+        readBytesOfEntry = bytesReadFromStream = 0L;
+        offsetInBuffer = lengthOfLastRead = 0;
         crc.reset();
         current = null;
         lastStoredEntry = null;



Mime
View raw message