Repository: commons-compress
Updated Branches:
  refs/heads/master 14b3d1ad8 -> 19a620c90


COMPRESS-355 properly deal with blank PAX header lines

Patch-by: Jeremy Gustie


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

Branch: refs/heads/master
Commit: 19a620c904587dc0397b43bfe9071ff60033c097
Parents: 14b3d1a
Author: Stefan Bodewig <[email protected]>
Authored: Fri May 20 18:18:05 2016 +0200
Committer: Stefan Bodewig <[email protected]>
Committed: Fri May 20 18:18:05 2016 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                            |   5 +++++
 .../archivers/tar/TarArchiveInputStream.java       |   4 +++-
 .../archivers/tar/TarArchiveInputStreamTest.java   |  16 ++++++++++++++++
 src/test/resources/COMPRESS-355.tar                | Bin 0 -> 8192 bytes
 4 files changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/19a620c9/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 72df227..276bb66 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -60,6 +60,11 @@ The <action> type attribute can be add,update,fix,remove.
         PureJavaCrc32C in the snappy package is now final so it is now
         safe to call a virtual method inside the constructor.
       </action>
+      <action issue="COMPRESS-355" type="fix" date="2016-05-20"
+              due-to="Jeremy Gustie">
+        TarArchiveInputStream failed to parse PAX headers that
+        included blank lines.
+      </action>
     </release>
     <release version="1.11" date="2016-04-06"
              description="Release 1.11">

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/19a620c9/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index 61b908f..f0d60cb 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -459,7 +459,9 @@ public class TarArchiveInputStream extends 
ArchiveInputStream {
             int read = 0;
             while((ch = i.read()) != -1) {
                 read++;
-                if (ch == ' '){ // End of length string
+                if (ch == '\n') { // blank line in header
+                    break;
+                } else if (ch == ' '){ // End of length string
                     // Get keyword
                     final ByteArrayOutputStream coll = new 
ByteArrayOutputStream();
                     while((ch = i.read()) != -1) {

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/19a620c9/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
----------------------------------------------------------------------
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
index 84f2e1d..015748b 100644
--- 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
@@ -23,6 +23,7 @@ import static 
org.apache.commons.compress.AbstractTestCase.mkdir;
 import static org.apache.commons.compress.AbstractTestCase.rmdir;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -297,6 +298,21 @@ public class TarArchiveInputStreamTest {
         }
     }
 
+    /**
+     * @link "https://issues.apache.org/jira/browse/COMPRESS-355";
+     */
+    @Test
+    public void survivesBlankLinesInPaxHeader() throws Exception {
+        final TarArchiveInputStream is = getTestStream("/COMPRESS-355.tar");
+        try {
+            final TarArchiveEntry entry = is.getNextTarEntry();
+            assertEquals("package/package.json", entry.getName());
+            assertNull(is.getNextTarEntry());
+        } finally {
+            is.close();
+        }
+    }
+
     private TarArchiveInputStream getTestStream(final String name) {
         return new TarArchiveInputStream(
                 TarArchiveInputStreamTest.class.getResourceAsStream(name));

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/19a620c9/src/test/resources/COMPRESS-355.tar
----------------------------------------------------------------------
diff --git a/src/test/resources/COMPRESS-355.tar 
b/src/test/resources/COMPRESS-355.tar
new file mode 100644
index 0000000..6eb94f2
Binary files /dev/null and b/src/test/resources/COMPRESS-355.tar differ

Reply via email to