commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ebo...@apache.org
Subject svn commit: r1552252 - /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Date Thu, 19 Dec 2013 08:51:48 GMT
Author: ebourg
Date: Thu Dec 19 08:51:47 2013
New Revision: 1552252

URL: http://svn.apache.org/r1552252
Log:
Update the entry CRC in the main read() method only (fixes the CRC for stored entries with
a data descriptor)

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=1552252&r1=1552251&r2=1552252&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 Dec 19 08:51:47 2013
@@ -384,26 +384,31 @@ public class ZipArchiveInputStream exten
         }
 
         // avoid int overflow, check null buffer
-        if (offset <= buffer.length && length >= 0 && offset >=
0
-            && buffer.length - offset >= length) {
-            ZipUtil.checkRequestedFeatures(current.entry);
-            if (!supportsDataDescriptorFor(current.entry)) {
-                throw new UnsupportedZipFeatureException(UnsupportedZipFeatureException
-                                                         .Feature
-                                                         .DATA_DESCRIPTOR,
-                                                         current.entry);
-            }
-
-            if (current.entry.getMethod() == ZipArchiveOutputStream.STORED) {
-                return readStored(buffer, offset, length);
-            }
-            if (current.entry.getMethod() == ZipMethod.UNSHRINKING.getCode()) {
-                throw new UnsupportedZipFeatureException(ZipMethod.UNSHRINKING,
-                                                         current.entry);
-            }
-            return readDeflated(buffer, offset, length);
+        if (offset > buffer.length || length < 0 || offset < 0 || buffer.length
- offset < length) {
+            throw new ArrayIndexOutOfBoundsException();
+        }
+        
+        ZipUtil.checkRequestedFeatures(current.entry);
+        if (!supportsDataDescriptorFor(current.entry)) {
+            throw new UnsupportedZipFeatureException(UnsupportedZipFeatureException.Feature.DATA_DESCRIPTOR,
+                    current.entry);
         }
-        throw new ArrayIndexOutOfBoundsException();
+
+        int read;
+        if (current.entry.getMethod() == ZipArchiveOutputStream.STORED) {
+            read = readStored(buffer, offset, length);
+        } else if (current.entry.getMethod() == ZipArchiveOutputStream.DEFLATED) {
+            read = readDeflated(buffer, offset, length);
+        } else {
+            throw new UnsupportedZipFeatureException(ZipMethod.getMethodByCode(current.entry.getMethod()),
+                    current.entry);
+        }
+        
+        if (read >= 0) {
+            crc.update(buffer, offset, read);
+        }
+        
+        return read;
     }
 
     /**
@@ -443,7 +448,6 @@ public class ZipArchiveInputStream exten
         }
         buf.get(buffer, offset, toRead);
         current.bytesRead += toRead;
-        crc.update(buffer, offset, toRead);
         return toRead;
     }
 
@@ -464,7 +468,6 @@ public class ZipArchiveInputStream exten
                 throw new IOException("Truncated ZIP file");
             }
         }
-        crc.update(buffer, offset, read);
         return read;
     }
 



Mime
View raw message