You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by oa...@apache.org on 2020/03/23 11:16:27 UTC

[camel] branch master updated: CAMEL-14752: Throw an exception on corrupted tarfiles

This is an automated email from the ASF dual-hosted git repository.

oalsafi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 27777aa  CAMEL-14752: Throw an exception on corrupted tarfiles
     new 0370662  Merge pull request #3664 from omarsmak/CAMEL-14752
27777aa is described below

commit 27777aa591ba531e6509a406cd986b217a645935
Author: Omar Al-Safi <om...@gmail.com>
AuthorDate: Mon Mar 23 12:10:16 2020 +0100

    CAMEL-14752: Throw an exception on corrupted tarfiles
---
 .../org/apache/camel/dataformat/tarfile/TarFileDataFormat.java     | 6 ++++--
 .../org/apache/camel/dataformat/tarfile/TarFileDataFormatTest.java | 7 +++++++
 components/camel-tarfile/src/test/resources/data/corrupt.tar       | 1 +
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/components/camel-tarfile/src/main/java/org/apache/camel/dataformat/tarfile/TarFileDataFormat.java b/components/camel-tarfile/src/main/java/org/apache/camel/dataformat/tarfile/TarFileDataFormat.java
index 0444f0a..2589795 100644
--- a/components/camel-tarfile/src/main/java/org/apache/camel/dataformat/tarfile/TarFileDataFormat.java
+++ b/components/camel-tarfile/src/main/java/org/apache/camel/dataformat/tarfile/TarFileDataFormat.java
@@ -90,7 +90,7 @@ public class TarFileDataFormat extends ServiceSupport implements DataFormat, Dat
         }
 
         String newFilename = filename + ".tar";
-        exchange.getOut().setHeader(FILE_NAME, newFilename);
+        exchange.getMessage().setHeader(FILE_NAME, newFilename);
     }
 
     @Override
@@ -107,8 +107,10 @@ public class TarFileDataFormat extends ServiceSupport implements DataFormat, Dat
             try {
                 TarArchiveEntry entry = tis.getNextTarEntry();
                 if (entry != null) {
-                    exchange.getOut().setHeader(FILE_NAME, entry.getName());
+                    exchange.getMessage().setHeader(FILE_NAME, entry.getName());
                     IOHelper.copy(tis, osb);
+                } else {
+                    throw new IllegalStateException("Unable to untar the file, it may be corrupted.");
                 }
 
                 entry = tis.getNextTarEntry();
diff --git a/components/camel-tarfile/src/test/java/org/apache/camel/dataformat/tarfile/TarFileDataFormatTest.java b/components/camel-tarfile/src/test/java/org/apache/camel/dataformat/tarfile/TarFileDataFormatTest.java
index 9b55902..64f3c4f 100644
--- a/components/camel-tarfile/src/test/java/org/apache/camel/dataformat/tarfile/TarFileDataFormatTest.java
+++ b/components/camel-tarfile/src/test/java/org/apache/camel/dataformat/tarfile/TarFileDataFormatTest.java
@@ -27,6 +27,7 @@ import java.nio.file.Paths;
 import java.util.Iterator;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.camel.CamelExecutionException;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.NotifyBuilder;
@@ -122,6 +123,11 @@ public class TarFileDataFormatTest extends CamelTestSupport {
         assertMockEndpointsSatisfied();
     }
 
+    @Test(expected = CamelExecutionException.class)
+    public void testUntarWithCorruptedTarFile() throws Exception {
+        template.sendBody("direct:corruptUntar", new File("src/test/resources/data/corrupt.tar"));
+    }
+
     @Test
     public void testTarAndUntar() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:tarAndUntar");
@@ -292,6 +298,7 @@ public class TarFileDataFormatTest extends CamelTestSupport {
                 from("direct:tarToFile").marshal(tar).to("file:" + TEST_DIR.getPath()).to("mock:tarToFile");
                 from("direct:dslTar").marshal(tar).to("mock:dslTar");
                 from("direct:dslUntar").unmarshal(tar).to("mock:dslUntar");
+                from("direct:corruptUntar").unmarshal(tar).to("mock:corruptUntar");
             }
         };
     }
diff --git a/components/camel-tarfile/src/test/resources/data/corrupt.tar b/components/camel-tarfile/src/test/resources/data/corrupt.tar
new file mode 100644
index 0000000..fc74404
--- /dev/null
+++ b/components/camel-tarfile/src/test/resources/data/corrupt.tar
@@ -0,0 +1 @@
+I am corrupted
\ No newline at end of file