commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject commons-compress git commit: COMPRESS-348 7z fails to read from empty entries.
Date Sun, 24 Apr 2016 11:22:56 GMT
Repository: commons-compress
Updated Branches:
  refs/heads/master ff5158b16 -> d0501577d


COMPRESS-348 7z fails to read from empty entries.


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

Branch: refs/heads/master
Commit: d0501577d37b594c3ff59a39ac211f7a1b170fa7
Parents: ff5158b
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sun Apr 24 13:21:52 2016 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sun Apr 24 13:22:34 2016 +0200

----------------------------------------------------------------------
 .../compress/archivers/sevenz/SevenZFile.java   |   3 +++
 .../archivers/sevenz/SevenZFileTest.java        |  25 +++++++++++++++++++
 src/test/resources/COMPRESS-348.7z              | Bin 0 -> 213 bytes
 3 files changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d0501577/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
index 3e2113d..1056840 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
@@ -899,6 +899,9 @@ public class SevenZFile implements Closeable {
     }
     
     private InputStream getCurrentStream() throws IOException {
+        if (archive.files[currentEntryIndex].getSize() == 0) {
+            return new ByteArrayInputStream(new byte[0]);
+        }
         if (deferredBlockStreams.isEmpty()) {
             throw new IllegalStateException("No current 7z entry (call getNextEntry() first).");
         }

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d0501577/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
index 1c514d8..beb0d7f 100644
--- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
@@ -259,6 +259,31 @@ public class SevenZFileTest extends AbstractTestCase {
             sevenZFile.close();
         }
     }
+
+    /**
+     * @see "https://issues.apache.org/jira/browse/COMPRESS-348"
+     */
+    @Test
+    public void readEntriesOfSize0() throws IOException {
+        final SevenZFile sevenZFile = new SevenZFile(getFile("COMPRESS-348.7z"));
+        try {
+            int entries = 0;
+            SevenZArchiveEntry entry = sevenZFile.getNextEntry();
+            while (entry != null) {
+                entries++;
+                int b = sevenZFile.read();
+                if ("2.txt".equals(entry.getName()) || "5.txt".equals(entry.getName())) {
+                    assertEquals(-1, b);
+                } else {
+                    assertNotEquals(-1, b);
+                }
+                entry = sevenZFile.getNextEntry();
+            }
+            assertEquals(5, entries);
+        } finally {
+            sevenZFile.close();
+        }
+    }
     
     private void test7zUnarchive(final File f, final SevenZMethod m, final byte[] password)
throws Exception {
         final SevenZFile sevenZFile = new SevenZFile(f, password);

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/d0501577/src/test/resources/COMPRESS-348.7z
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-348.7z b/src/test/resources/COMPRESS-348.7z
new file mode 100644
index 0000000..8fb26c2
Binary files /dev/null and b/src/test/resources/COMPRESS-348.7z differ


Mime
View raw message