diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index d3ea7522e..72d285856 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -356,6 +356,7 @@ Ulrich Schmidt
Valentino Miazzo
Victor Toni
Vincent Legoll
+Volker Leidl
Waldek Herka
Will Wang
William Bernardet
diff --git a/WHATSNEW b/WHATSNEW
index 40675b0b2..43f3427ae 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -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:
--------------
diff --git a/contributors.xml b/contributors.xml
index bbf430258..b22916a9b 100644
--- a/contributors.xml
+++ b/contributors.xml
@@ -1436,6 +1436,10 @@
Vincent
Legoll
+
+ Volker
+ Leidl
+
Will
Wang
diff --git a/src/main/org/apache/tools/zip/ZipFile.java b/src/main/org/apache/tools/zip/ZipFile.java
index b2309d136..6614fe4c9 100644
--- a/src/main/org/apache/tools/zip/ZipFile.java
+++ b/src/main/org/apache/tools/zip/ZipFile.java
@@ -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);
}
}
}
diff --git a/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java b/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java
index 820c39f51..8f8158ae0 100644
--- a/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java
+++ b/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java
@@ -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 TestCase {
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 TestCase {
}
}
+ 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();
+ }
+ }
+
}