commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1153850 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/zip/ test/java/org/apache/commons/compress/archivers/zip/
Date Thu, 04 Aug 2011 11:26:49 GMT
Author: bodewig
Date: Thu Aug  4 11:26:48 2011
New Revision: 1153850

URL: http://svn.apache.org/viewvc?rev=1153850&view=rev
Log:
if the central directory header holds only one of the size values, the other one must still
be set so the internal logic for handling of extra fields doesn't throw an exception creating
the local file header data.  COMPRESS-149

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

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java?rev=1153850&r1=1153849&r2=1153850&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraField.java
Thu Aug  4 11:26:48 2011
@@ -182,6 +182,13 @@ public class Zip64ExtendedInformationExt
     /** {@inheritDoc} */
     public void parseFromLocalFileData(byte[] buffer, int offset, int length)
         throws ZipException {
+        if (length == 0) {
+            // no local file data at all, may happen if an archive
+            // only holds a ZIP64 extended information extra field
+            // inside the central directory but not inside the local
+            // file header
+            return;
+        }
         if (length < 2 * DWORD) {
             throw new ZipException(LFH_MUST_HAVE_BOTH_SIZES_MSG);
         }

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=1153850&r1=1153849&r2=1153850&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 11:26:48 2011
@@ -482,20 +482,34 @@ public class ZipFile {
                 ze.getExtraField(Zip64ExtendedInformationExtraField
                                  .HEADER_ID);
             if (z64 != null) {
-                z64.reparseCentralDirectoryData(ze.getSize() == ZIP64_MAGIC,
-                                                ze.getCompressedSize()
-                                                == ZIP64_MAGIC,
-                                                offset.headerOffset
-                                                == ZIP64_MAGIC,
+                boolean hasUncompressedSize = ze.getSize() == ZIP64_MAGIC;
+                boolean hasCompressedSize =
+                    ze.getCompressedSize() == ZIP64_MAGIC;
+                boolean hasRelativeHeaderOffset = 
+                    offset.headerOffset == ZIP64_MAGIC;
+                z64.reparseCentralDirectoryData(hasUncompressedSize,
+                                                hasCompressedSize,
+                                                hasRelativeHeaderOffset,
                                                 diskStart == ZIP64_MAGIC_SHORT);
-                if (ze.getSize() == ZIP64_MAGIC) {
+
+                // read ZIP64 values into entry.
+                // ensure ZIP64 field either knows no or both size
+                // values so it can create valid local header extra data
+
+                if (hasUncompressedSize) {
                     ze.setSize(z64.getSize().getLongValue());
+                } else if (hasCompressedSize) {
+                    z64.setSize(new ZipEightByteInteger(ze.getSize()));
                 }
-                if (ze.getCompressedSize() == ZIP64_MAGIC) {
+
+                if (hasCompressedSize) {
                     ze.setCompressedSize(z64.getCompressedSize()
                                          .getLongValue());
+                } else if (hasUncompressedSize) {
+                    z64.setCompressedSize(new ZipEightByteInteger(ze.getCompressedSize()));
                 }
-                if (offset.headerOffset == ZIP64_MAGIC) {
+
+                if (hasRelativeHeaderOffset) {
                     offset.headerOffset =
                         z64.getRelativeHeaderOffset().getLongValue();
                 }

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java?rev=1153850&r1=1153849&r2=1153850&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportTest.java
Thu Aug  4 11:26:48 2011
@@ -96,7 +96,6 @@ public class Zip64SupportTest {
                                        "5GB_of_Zeros");
     }
 
-    @Ignore
     @Test public void read5GBOfZerosGeneratedByJava7JarUsingZipFile()
         throws Throwable {
         read5GBOfZerosUsingZipFileImpl(get5GBZerosFileGeneratedByJava7Jar(),
@@ -223,6 +222,7 @@ public class Zip64SupportTest {
         withTemporaryArchive("write100KFilesFile", write100KFiles, true);
     }
 
+    @Ignore
     @Test public void write100KFilesStream() throws Throwable {
         withTemporaryArchive("write100KFilesStream", write100KFiles, false);
     }



Mime
View raw message