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 2015/08/22 21:01:32 UTC

svn commit: r1697106 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java

Author: bodewig
Date: Sat Aug 22 19:01:32 2015
New Revision: 1697106

URL: http://svn.apache.org/r1697106
Log:
COMPRESS-321 X7875_NewUnix doesn't handle centra directory correctly

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.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=1697106&r1=1697105&r2=1697106&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Sat Aug 22 19:01:32 2015
@@ -44,6 +44,10 @@ The <action> type attribute can be add,u
   <body>
     <release version="1.11" date="not released, yet"
              description="Release 1.11">
+      <action issue="COMPRESS-321" type="fix" date="2015-08-22">
+        ArrayIndexOutOfBoundsException when InfoZIP type 7875 extra
+        fields are read from the central directory.
+      </action>
     </release>
 
     <release version="1.10" date="2015-08-18"

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java?rev=1697106&r1=1697105&r2=1697106&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java Sat Aug 22 19:01:32 2015
@@ -32,6 +32,8 @@ import static org.apache.commons.compres
  * zip-3.0.tar.gz/proginfo/extrafld.txt
  *
  * <pre>
+ * Local-header version:
+ *
  * Value         Size        Description
  * -----         ----        -----------
  * 0x7875        Short       tag for this extra block type ("ux")
@@ -41,11 +43,19 @@ import static org.apache.commons.compres
  * UID           Variable    UID for this entry (little endian)
  * GIDSize       1 byte      Size of GID field
  * GID           Variable    GID for this entry (little endian)
+ *
+ * Central-header version:
+ *
+ * Value         Size        Description
+ * -----         ----        -----------
+ * 0x7855        Short       tag for this extra block type ("Ux")
+ * TSize         Short       total data size for this block (0)
  * </pre>
  * @since 1.5
  */
 public class X7875_NewUnix implements ZipExtraField, Cloneable, Serializable {
     private static final ZipShort HEADER_ID = new ZipShort(0x7875);
+    private static final ZipShort ZERO = new ZipShort(0);
     private static final BigInteger ONE_THOUSAND = BigInteger.valueOf(1000);
     private static final long serialVersionUID = 1L;
 
@@ -134,7 +144,7 @@ public class X7875_NewUnix implements Zi
      * @return a <code>ZipShort</code> for the length of the data of this extra field
      */
     public ZipShort getCentralDirectoryLength() {
-        return getLocalFileDataLength();  // No different than local version.
+        return ZERO;
     }
 
     /**
@@ -181,7 +191,7 @@ public class X7875_NewUnix implements Zi
      * @return get the data
      */
     public byte[] getCentralDirectoryData() {
-        return getLocalFileDataData();
+        return new byte[0];
     }
 
     /**
@@ -210,14 +220,12 @@ public class X7875_NewUnix implements Zi
     }
 
     /**
-     * Doesn't do anything special since this class always uses the
-     * same data in central directory and local file data.
+     * Doesn't do anything since this class doesn't store anything
+     * inside the central directory.
      */
     public void parseFromCentralDirectoryData(
             byte[] buffer, int offset, int length
     ) throws ZipException {
-        reset();
-        parseFromLocalFileData(buffer, offset, length);
     }
 
     /**

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java?rev=1697106&r1=1697105&r2=1697106&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java (original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/X7875_NewUnixTest.java Sat Aug 22 19:01:32 2015
@@ -27,6 +27,7 @@ import java.util.Enumeration;
 import java.util.zip.ZipException;
 
 import static org.apache.commons.compress.AbstractTestCase.getFile;
+import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
@@ -207,13 +208,6 @@ public class X7875_NewUnixTest {
         assertEquals(expectedUID, xf.getUID());
         assertEquals(expectedGID, xf.getGID());
 
-        // Initial central parse (init with garbage to avoid defaults causing test to pass).
-        xf.setUID(54321);
-        xf.setGID(12345);
-        xf.parseFromCentralDirectoryData(expected, 0, expected.length);
-        assertEquals(expectedUID, xf.getUID());
-        assertEquals(expectedGID, xf.getGID());
-
         xf.setUID(uid);
         xf.setGID(gid);
         if (expected.length < 5) {
@@ -239,22 +233,9 @@ public class X7875_NewUnixTest {
         assertEquals(expectedUID, xf.getUID());
         assertEquals(expectedGID, xf.getGID());
 
-        // Do the same as above, but with Central Directory data:
-        xf.setUID(uid);
-        xf.setGID(gid);
-        if (expected.length < 5) {
-            // We never emit zero-length entries.
-            assertEquals(5, xf.getCentralDirectoryLength().getValue());
-        } else {
-            assertEquals(expected.length, xf.getCentralDirectoryLength().getValue());
-        }
+        assertEquals(0, xf.getCentralDirectoryLength().getValue());
         result = xf.getCentralDirectoryData();
-        if (expected.length < 5) {
-            // We never emit zero-length entries.
-            assertTrue(Arrays.equals(new byte[]{1,1,0,1,0}, result));
-        } else {
-            assertTrue(Arrays.equals(expected, result));
-        }
+        assertArrayEquals(new byte[0], result);
 
         // And now we re-parse:
         xf.parseFromCentralDirectoryData(result, 0, result.length);