You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2011/12/05 17:32:31 UTC

svn commit: r1210522 - in /ant/core/trunk: CONTRIBUTORS WHATSNEW contributors.xml src/main/org/apache/tools/zip/ZipFile.java src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java

Author: bodewig
Date: Mon Dec  5 16:32:30 2011
New Revision: 1210522

URL: http://svn.apache.org/viewvc?rev=1210522&view=rev
Log:
ZipFile doesn't work properly for archives using unicode extra fields.  Port of fix for COMPRESS-164 by Volker Leidl

Modified:
    ant/core/trunk/CONTRIBUTORS
    ant/core/trunk/WHATSNEW
    ant/core/trunk/contributors.xml
    ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java
    ant/core/trunk/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java

Modified: ant/core/trunk/CONTRIBUTORS
URL: http://svn.apache.org/viewvc/ant/core/trunk/CONTRIBUTORS?rev=1210522&r1=1210521&r2=1210522&view=diff
==============================================================================
--- ant/core/trunk/CONTRIBUTORS (original)
+++ ant/core/trunk/CONTRIBUTORS Mon Dec  5 16:32:30 2011
@@ -356,6 +356,7 @@ Ulrich Schmidt
 Valentino Miazzo
 Victor Toni
 Vincent Legoll
+Volker Leidl
 Waldek Herka
 Will Wang
 William Bernardet

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1210522&r1=1210521&r2=1210522&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Dec  5 16:32:30 2011
@@ -112,6 +112,9 @@ Fixed bugs:
    quoted.
    Bugzilla Report 31667.
 
+ * ZipFile didn't work properly for archives using unicode extra
+   fields rather than UTF-8 filenames and the EFS-Flag.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/contributors.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/contributors.xml?rev=1210522&r1=1210521&r2=1210522&view=diff
==============================================================================
--- ant/core/trunk/contributors.xml (original)
+++ ant/core/trunk/contributors.xml Mon Dec  5 16:32:30 2011
@@ -1437,6 +1437,10 @@
     <last>Legoll</last>
   </name>
   <name>
+    <first>Volker</first>
+    <last>Leidl</last>
+  </name>
+  <name>
     <first>Will</first>
     <last>Wang</last>
   </name>

Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java?rev=1210522&r1=1210521&r2=1210522&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java Mon Dec  5 16:32:30 2011
@@ -27,6 +27,7 @@ import java.util.Collections;
 import java.util.Date;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.zip.CRC32;
 import java.util.zip.Inflater;
@@ -509,7 +510,7 @@ public class ZipFile {
      */
     private void resolveLocalFileHeaderData(Map entriesWithoutUTF8Flag)
         throws IOException {
-        Enumeration e = getEntries();
+        Enumeration e = Collections.enumeration(new HashSet(entries.keySet()));
         while (e.hasMoreElements()) {
             ZipEntry ze = (ZipEntry) e.nextElement();
             OffsetEntry offsetEntry = (OffsetEntry) entries.get(ze);
@@ -540,9 +541,14 @@ public class ZipFile {
                 + SHORT + SHORT + fileNameLen + extraFieldLen;
 
             if (entriesWithoutUTF8Flag.containsKey(ze)) {
+                // changing the name of a ZipEntry is going to change
+                // the hashcode
+                // - see https://issues.apache.org/jira/browse/COMPRESS-164
+                entries.remove(ze);
                 setNameAndCommentFromExtraFields(ze,
                                                  (NameAndComment)
                                                  entriesWithoutUTF8Flag.get(ze));
+                entries.put(ze, offsetEntry);
             }
         }
     }

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java?rev=1210522&r1=1210521&r2=1210522&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java Mon Dec  5 16:32:30 2011
@@ -19,6 +19,7 @@
 package org.apache.tools.zip;
 
 import java.io.File;
+import java.io.InputStream;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.nio.ByteBuffer;
@@ -81,9 +82,9 @@ public class UTF8ZipFilesTest extends Te
         try {
             createTestFile(file, US_ASCII, false, true);
             zf = new ZipFile(file, US_ASCII, true);
-            assertNotNull(zf.getEntry(ASCII_TXT));
-            assertNotNull(zf.getEntry(EURO_FOR_DOLLAR_TXT));
-            assertNotNull(zf.getEntry(OIL_BARREL_TXT));
+            assertCanRead(zf, ASCII_TXT);
+            assertCanRead(zf, EURO_FOR_DOLLAR_TXT);
+            assertCanRead(zf, OIL_BARREL_TXT);
         } finally {
             ZipFile.closeQuietly(zf);
             if (file.exists()) {
@@ -232,5 +233,17 @@ public class UTF8ZipFilesTest extends Te
         }
     }
 
+    private static void assertCanRead(ZipFile zf, String fileName) throws IOException {
+        ZipEntry entry = zf.getEntry(fileName);
+        assertNotNull("Entry " + fileName + " doesn't exist", entry);
+        InputStream is = zf.getInputStream(entry);
+        assertNotNull("InputStream is null", is);
+        try {
+            is.read();
+        } finally {
+            is.close();
+        }
+    }
+
 }