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 2012/02/28 06:00:27 UTC

svn commit: r1294460 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/zip/ test/java/org/apache/commons/compress/archivers/zip/ test/resources/

Author: bodewig
Date: Tue Feb 28 05:00:26 2012
New Revision: 1294460

URL: http://svn.apache.org/viewvc?rev=1294460&view=rev
Log:
add workaround for broken implementations that use backslashes rather than slashes in file names.  COMPRESS-176

Added:
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java   (with props)
    commons/proper/compress/trunk/src/test/resources/test-winzip.zip   (with props)
Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.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=1294460&r1=1294459&r2=1294460&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Tue Feb 28 05:00:26 2012
@@ -46,6 +46,10 @@ The <action> type attribute can be add,u
   <body>
     <release version="1.4" date="unreleased"
              description="Release 1.4">
+      <action issue="COMPRESS-176" type="update" date="2012-02-28">
+        Added a workaround for a Bug in WinZIP which uses backslashes
+        as path separators in Unicode Extra Fields.
+      </action> 
       <action issue="COMPRESS-131" type="update" date="2012-02-23">
         ArrayOutOfBounds while decompressing bz2. Added test case - code already seems to have been fixed.
       </action> 

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java?rev=1294460&r1=1294459&r2=1294460&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java Tue Feb 28 05:00:26 2012
@@ -509,6 +509,10 @@ public class ZipArchiveEntry extends jav
      * @param name the name to use
      */
     protected void setName(String name) {
+        if (name != null && getPlatform() == PLATFORM_FAT
+            && name.indexOf("/") == -1) {
+            name = name.replace('\\', '/');
+        }
         this.name = name;
     }
 

Added: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java?rev=1294460&view=auto
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java (added)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java Tue Feb 28 05:00:26 2012
@@ -0,0 +1,51 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.commons.compress.archivers.zip;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.net.URI;
+import java.net.URL;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class ZipArchiveInputStreamTest {
+
+    /**
+     * @see https://issues.apache.org/jira/browse/COMPRESS-176
+     */
+    @Test
+    public void winzipBackSlashWorkaround() throws Exception {
+        URL zip = getClass().getResource("/test-winzip.zip");
+        ZipArchiveInputStream in = null;
+        try {
+            in = new ZipArchiveInputStream(new FileInputStream(new File(new URI(zip.toString()))));
+            ZipArchiveEntry zae = in.getNextZipEntry();
+            zae = in.getNextZipEntry();
+            zae = in.getNextZipEntry();
+            assertEquals("\u00e4/", zae.getName());
+        } finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+    }
+
+}
\ No newline at end of file

Propchange: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java?rev=1294460&r1=1294459&r2=1294460&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java (original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java Tue Feb 28 05:00:26 2012
@@ -139,6 +139,17 @@ public class ZipFileTest extends TestCas
         }
     }
 
+    /**
+     * @see https://issues.apache.org/jira/browse/COMPRESS-176
+     */
+    public void testWinzipBackSlashWorkaround() throws Exception {
+        URL zip = getClass().getResource("/test-winzip.zip");
+        File archive = new File(new URI(zip.toString()));
+        zf = new ZipFile(archive);
+        assertNull(zf.getEntry("\u00e4\\\u00fc.txt"));
+        assertNotNull(zf.getEntry("\u00e4/\u00fc.txt"));
+    }
+
     /*
      * ordertest.zip has been handcrafted.
      *

Added: commons/proper/compress/trunk/src/test/resources/test-winzip.zip
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/test-winzip.zip?rev=1294460&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/proper/compress/trunk/src/test/resources/test-winzip.zip
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Re: svn commit: r1294460 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/zip/ test/java/org/apache/commons/compress/archivers/zip/ test/resources/

Posted by Stefan Bodewig <bo...@apache.org>.
On 2012-02-28, sebb wrote:

> On 28 February 2012 05:00,  <bo...@apache.org> wrote:
>>     protected void setName(String name) {
>>+         if (name != null && getPlatform() == PLATFORM_FAT
>>+             && name.indexOf("/") == -1) {
>>+             name = name.replace('\\', '/');
>>+         }
>>         this.name = name;
>>     }

> The original problem is with unicode extra fields only.

The InfoZIP workaround replicated here is not conditional, it seems
there are other broken ZIPs that use backslashes in plain names as well.

Stefan

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1294460 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/zip/ test/java/org/apache/commons/compress/archivers/zip/ test/resources/

Posted by sebb <se...@gmail.com>.
On 28 February 2012 05:00,  <bo...@apache.org> wrote:
> Author: bodewig
> Date: Tue Feb 28 05:00:26 2012
> New Revision: 1294460
>
> URL: http://svn.apache.org/viewvc?rev=1294460&view=rev
> Log:
> add workaround for broken implementations that use backslashes rather than slashes in file names.  COMPRESS-176
>
> Added:
>    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java   (with props)
>    commons/proper/compress/trunk/src/test/resources/test-winzip.zip   (with props)
> Modified:
>    commons/proper/compress/trunk/src/changes/changes.xml
>    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
>    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.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=1294460&r1=1294459&r2=1294460&view=diff
> ==============================================================================
> --- commons/proper/compress/trunk/src/changes/changes.xml (original)
> +++ commons/proper/compress/trunk/src/changes/changes.xml Tue Feb 28 05:00:26 2012
> @@ -46,6 +46,10 @@ The <action> type attribute can be add,u
>   <body>
>     <release version="1.4" date="unreleased"
>              description="Release 1.4">
> +      <action issue="COMPRESS-176" type="update" date="2012-02-28">
> +        Added a workaround for a Bug in WinZIP which uses backslashes
> +        as path separators in Unicode Extra Fields.
> +      </action>
>       <action issue="COMPRESS-131" type="update" date="2012-02-23">
>         ArrayOutOfBounds while decompressing bz2. Added test case - code already seems to have been fixed.
>       </action>
>
> Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java
> URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java?rev=1294460&r1=1294459&r2=1294460&view=diff
> ==============================================================================
> --- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java (original)
> +++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveEntry.java Tue Feb 28 05:00:26 2012
> @@ -509,6 +509,10 @@ public class ZipArchiveEntry extends jav
>      * @param name the name to use
>      */
>     protected void setName(String name) {
> +        if (name != null && getPlatform() == PLATFORM_FAT
> +            && name.indexOf("/") == -1) {
> +            name = name.replace('\\', '/');
> +        }
>         this.name = name;
>     }

The original problem is with unicode extra fields only.

Would it not be safer to apply the fix to the method
setNameAndCommentFromExtraFields where it actually calls setName?

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org