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 953ab78 CAMEL-14748: Throw an error with corrupt zip file new e1ed962 Merge pull request #3657 from omarsmak/CAMEL-14748 953ab78 is described below commit 953ab78259068e4c59e1b6c9d080ae1b95083c23 Author: Omar Al-Safi <omars...@gmail.com> AuthorDate: Fri Mar 20 16:48:05 2020 +0100 CAMEL-14748: Throw an error with corrupt zip file --- .../apache/camel/dataformat/zipfile/ZipFileDataFormat.java | 2 ++ .../camel/dataformat/zipfile/ZipFileDataFormatTest.java | 11 +++++++++++ components/camel-zipfile/src/test/resources/corrupt.zip | 1 + 3 files changed, 14 insertions(+) diff --git a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java index fe889f5..f168642 100644 --- a/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java +++ b/components/camel-zipfile/src/main/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormat.java @@ -98,6 +98,8 @@ public class ZipFileDataFormat extends ServiceSupport implements DataFormat, Dat if (entry != null) { exchange.getMessage().setHeader(FILE_NAME, entry.getName()); IOHelper.copy(zis, osb); + } else { + throw new IllegalStateException("Unable to unzip the file, it may be corrupted."); } entry = zis.getNextEntry(); diff --git a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java index 2b65c0b..31115a0 100644 --- a/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java +++ b/components/camel-zipfile/src/test/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatTest.java @@ -32,6 +32,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; +import org.apache.camel.CamelExecutionException; import org.apache.camel.Exchange; import org.apache.camel.Processor; import org.apache.camel.builder.NotifyBuilder; @@ -156,6 +157,15 @@ public class ZipFileDataFormatTest extends CamelTestSupport { deleteDirectory(new File("hello_out")); } + @Test(expected = CamelExecutionException.class) + public void testUnzipWithCorruptedZipFile() throws Exception { + deleteDirectory(new File("hello_out")); + + template.sendBody("direct:corruptUnzip", new File("src/test/resources/corrupt.zip")); + + deleteDirectory(new File("hello_out")); + } + @Test public void testZipAndUnzip() throws Exception { MockEndpoint mock = getMockEndpoint("mock:zipAndUnzip"); @@ -304,6 +314,7 @@ public class ZipFileDataFormatTest extends CamelTestSupport { from("direct:zipToFile").marshal(zip).to("file:" + TEST_DIR.getPath()).to("mock:zipToFile"); from("direct:dslZip").marshal().zipFile().to("mock:dslZip"); from("direct:dslUnzip").unmarshal().zipFile().to("mock:dslUnzip"); + from("direct:corruptUnzip").unmarshal().zipFile().to("mock:corruptUnzip"); from("direct:zipStreamCache").streamCaching().marshal().zipFile().to("mock:zipStreamCache"); } }; diff --git a/components/camel-zipfile/src/test/resources/corrupt.zip b/components/camel-zipfile/src/test/resources/corrupt.zip new file mode 100644 index 0000000..fc74404 --- /dev/null +++ b/components/camel-zipfile/src/test/resources/corrupt.zip @@ -0,0 +1 @@ +I am corrupted \ No newline at end of file