Repository: commons-compress
Updated Branches:
  refs/heads/master 2cc332cc2 -> ddb8f08c7


COMPRESS-351 try to sanitize entry name in exception message


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/ddb8f08c
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/ddb8f08c
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/ddb8f08c

Branch: refs/heads/master
Commit: ddb8f08c79b8568c9cba3af61fb5a613e0ccba22
Parents: 2cc332c
Author: Stefan Bodewig <bode...@apache.org>
Authored: Sun Apr 17 07:06:24 2016 +0200
Committer: Stefan Bodewig <bode...@apache.org>
Committed: Sun Apr 17 07:06:24 2016 +0200

----------------------------------------------------------------------
 .../archivers/zip/ZipArchiveInputStream.java      | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/ddb8f08c/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
index d64ae4e..47668fc 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
@@ -653,7 +653,12 @@ public class ZipArchiveInputStream extends 
ArchiveInputStream {
         while (remaining > 0) {
             final long n = in.read(buf.array(), 0, (int) 
Math.min(buf.capacity(), remaining));
             if (n < 0) {
-                throw new EOFException("Truncated ZIP entry: " + 
current.entry.getName());
+                String name = current.entry.getName();
+                int idx = firstUnprintableCharacter(current.entry.getName());
+                if (idx >= 0) {
+                    name = "corrupted name starting with '" + 
name.substring(0, idx) + "'";
+                }
+                throw new EOFException("Truncated ZIP entry: " + name);
             }
             count(n);
             remaining -= n;
@@ -983,6 +988,17 @@ public class ZipArchiveInputStream extends 
ArchiveInputStream {
         return b == ZipArchiveOutputStream.EOCD_SIG[0];
     }
 
+    private int firstUnprintableCharacter(String name) {
+        final char[] chars = name.toCharArray();
+        final int len = chars.length;
+        for (int i = 0; i < len; i++) {
+            if (Character.isISOControl(chars[i]) || 
!Character.isDefined(chars[i])) {
+                return i;
+            }
+        }
+        return -1;
+    }
+
     /**
      * Structure collecting information for the entry that is
      * currently being read.

Reply via email to