You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by co...@apache.org on 2020/10/02 13:25:45 UTC
[camel] branch camel-3.4.x updated: CAMEL-15591 - Put a
configurable limit on the size of unzipped data using camel-zipfile +
camel-tarfile (#4314)
This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch camel-3.4.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.4.x by this push:
new 65c7e14 CAMEL-15591 - Put a configurable limit on the size of unzipped data using camel-zipfile + camel-tarfile (#4314)
65c7e14 is described below
commit 65c7e142ad5e4fbe923d69f86f6823fdce1dc246
Author: Colm O hEigeartaigh <co...@users.noreply.github.com>
AuthorDate: Fri Oct 2 10:41:21 2020 +0100
CAMEL-15591 - Put a configurable limit on the size of unzipped data using camel-zipfile + camel-tarfile (#4314)
---
.../tarfile/TarFileDataFormatConfigurer.java | 2 ++
.../services/org/apache/camel/dataformat.properties | 2 +-
.../org/apache/camel/dataformat/tarfile/tarfile.json | 3 ++-
.../src/main/docs/tarfile-dataformat.adoc | 3 ++-
.../camel/dataformat/tarfile/TarFileDataFormat.java | 11 ++++++++++-
.../dataformat/tarfile/TarFileDataFormatTest.java | 12 ++++++++++++
.../zipfile/ZipFileDataFormatConfigurer.java | 2 ++
.../services/org/apache/camel/dataformat.properties | 2 +-
.../org/apache/camel/dataformat/zipfile/zipfile.json | 3 ++-
.../src/main/docs/zipfile-dataformat.adoc | 3 ++-
.../camel/dataformat/zipfile/ZipFileDataFormat.java | 11 ++++++++++-
.../dataformat/zipfile/ZipFileDataFormatTest.java | 12 ++++++++++++
.../org/apache/camel/model/dataformat/tarfile.json | 1 +
.../org/apache/camel/model/dataformat/zipfile.json | 1 +
.../camel/model/dataformat/TarFileDataFormat.java | 19 +++++++++++++++++++
.../camel/model/dataformat/ZipFileDataFormat.java | 17 +++++++++++++++++
.../reifier/dataformat/TarFileDataFormatReifier.java | 1 +
.../reifier/dataformat/ZipFileDataFormatReifier.java | 1 +
.../src/main/java/org/apache/camel/util/IOHelper.java | 14 +++++++++++++-
.../java/org/apache/camel/xml/in/ModelParser.java | 2 ++
.../modules/dataformats/pages/tarfile-dataformat.adoc | 3 ++-
.../modules/dataformats/pages/zipfile-dataformat.adoc | 3 ++-
22 files changed, 117 insertions(+), 11 deletions(-)
diff --git a/components/camel-tarfile/src/generated/java/org/apache/camel/dataformat/tarfile/TarFileDataFormatConfigurer.java b/components/camel-tarfile/src/generated/java/org/apache/camel/dataformat/tarfile/TarFileDataFormatConfigurer.java
index faaef7c..978c9af 100644
--- a/components/camel-tarfile/src/generated/java/org/apache/camel/dataformat/tarfile/TarFileDataFormatConfigurer.java
+++ b/components/camel-tarfile/src/generated/java/org/apache/camel/dataformat/tarfile/TarFileDataFormatConfigurer.java
@@ -24,6 +24,8 @@ public class TarFileDataFormatConfigurer extends PropertyConfigurerSupport imple
case "allowEmptyDirectory": dataformat.setAllowEmptyDirectory(property(camelContext, boolean.class, value)); return true;
case "preservepathelements":
case "preservePathElements": dataformat.setPreservePathElements(property(camelContext, boolean.class, value)); return true;
+ case "maxdecompressedsize":
+ case "maxDecompressedSize": dataformat.setMaxDecompressedSize(property(camelContext, long.class, value)); return true;
default: return false;
}
}
diff --git a/components/camel-tarfile/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties b/components/camel-tarfile/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
index 5559e6c..0a4dd66 100644
--- a/components/camel-tarfile/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
+++ b/components/camel-tarfile/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
@@ -2,6 +2,6 @@
dataFormats=tarfile
groupId=org.apache.camel
artifactId=camel-tarfile
-version=3.4.4-SNAPSHOT
+version=3.4.5-SNAPSHOT
projectName=Camel :: Tar File
projectDescription=Camel Tar file support
diff --git a/components/camel-tarfile/src/generated/resources/org/apache/camel/dataformat/tarfile/tarfile.json b/components/camel-tarfile/src/generated/resources/org/apache/camel/dataformat/tarfile/tarfile.json
index 529c189..c27d83e 100644
--- a/components/camel-tarfile/src/generated/resources/org/apache/camel/dataformat/tarfile/tarfile.json
+++ b/components/camel-tarfile/src/generated/resources/org/apache/camel/dataformat/tarfile/tarfile.json
@@ -11,7 +11,7 @@
"supportLevel": "Stable",
"groupId": "org.apache.camel",
"artifactId": "camel-tarfile",
- "version": "3.4.4-SNAPSHOT",
+ "version": "3.4.5-SNAPSHOT",
"modelName": "tarfile",
"modelJavaType": "org.apache.camel.model.dataformat.TarFileDataFormat"
},
@@ -19,6 +19,7 @@
"usingIterator": { "kind": "attribute", "displayName": "Using Iterator", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the tar file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode." },
"allowEmptyDirectory": { "kind": "attribute", "displayName": "Allow Empty Directory", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the tar file has more then one entry, setting this option to true, allows to get the iterator even if the directory is empty" },
"preservePathElements": { "kind": "attribute", "displayName": "Preserve Path Elements", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the file name contains path elements, setting this option to true, allows the path to be maintained in the tar file." },
+ "maxDecompressedSize": { "kind": "attribute", "displayName": "Max Decompressed Size", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "secret": false, "description": "Set the maximum decompressed size of a tar file (in bytes). An IOException will be thrown if the decompressed size exceeds this amount. Set to -1 to disable setting a maximum decompressed size. By default there is no maximum size enforced." },
"contentTypeHeader": { "kind": "attribute", "displayName": "Content Type Header", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshalling to JS [...]
"id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "The id of this node" }
}
diff --git a/components/camel-tarfile/src/main/docs/tarfile-dataformat.adoc b/components/camel-tarfile/src/main/docs/tarfile-dataformat.adoc
index fdf4510..9e24670 100644
--- a/components/camel-tarfile/src/main/docs/tarfile-dataformat.adoc
+++ b/components/camel-tarfile/src/main/docs/tarfile-dataformat.adoc
@@ -20,7 +20,7 @@ aggregate multiple messages into a single Tar File.
// dataformat options: START
-The Tar File dataformat supports 4 options, which are listed below.
+The Tar File dataformat supports 5 options, which are listed below.
@@ -30,6 +30,7 @@ The Tar File dataformat supports 4 options, which are listed below.
| usingIterator | false | Boolean | If the tar file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode.
| allowEmptyDirectory | false | Boolean | If the tar file has more then one entry, setting this option to true, allows to get the iterator even if the directory is empty
| preservePathElements | false | Boolean | If the file name contains path elements, setting this option to true, allows the path to be maintained in the tar file.
+| maxDecompressedSize | | Long | Set the maximum decompressed size of a tar file (in bytes). An IOException will be thrown if the decompressed size exceeds this amount. Set to -1 to disable setting a maximum decompressed size. By default there is no maximum size enforced.
| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc.
|===
// dataformat options: END
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 2589795..7dd1055 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
@@ -49,6 +49,7 @@ public class TarFileDataFormat extends ServiceSupport implements DataFormat, Dat
private boolean usingIterator;
private boolean allowEmptyDirectory;
private boolean preservePathElements;
+ private long maxDecompressedSize = -1;
@Override
public String getDataFormatName() {
@@ -108,7 +109,7 @@ public class TarFileDataFormat extends ServiceSupport implements DataFormat, Dat
TarArchiveEntry entry = tis.getNextTarEntry();
if (entry != null) {
exchange.getMessage().setHeader(FILE_NAME, entry.getName());
- IOHelper.copy(tis, osb);
+ IOHelper.copy(tis, osb, IOHelper.DEFAULT_BUFFER_SIZE, false, maxDecompressedSize);
} else {
throw new IllegalStateException("Unable to untar the file, it may be corrupted.");
}
@@ -175,6 +176,14 @@ public class TarFileDataFormat extends ServiceSupport implements DataFormat, Dat
this.preservePathElements = preservePathElements;
}
+ public long getMaxDecompressedSize() {
+ return maxDecompressedSize;
+ }
+
+ public void setMaxDecompressedSize(long maxDecompressedSize) {
+ this.maxDecompressedSize = maxDecompressedSize;
+ }
+
@Override
protected void doStart() throws Exception {
// noop
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 64f3c4f..65de7f0 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
@@ -227,6 +227,13 @@ public class TarFileDataFormatTest extends CamelTestSupport {
deleteDirectory(new File("hello_out"));
}
+ @Test
+ public void testUnzipMaxDecompressedSize() throws Exception {
+ // We are only allowing 10 bytes to be decompressed, so we expect an error
+ assertThrows(CamelExecutionException.class,
+ () -> template.sendBody("direct:untarMaxDecompressedSize", getTaredText("file")));
+ }
+
@Override
@Before
public void setUp() throws Exception {
@@ -299,6 +306,11 @@ public class TarFileDataFormatTest extends CamelTestSupport {
from("direct:dslTar").marshal(tar).to("mock:dslTar");
from("direct:dslUntar").unmarshal(tar).to("mock:dslUntar");
from("direct:corruptUntar").unmarshal(tar).to("mock:corruptUntar");
+
+ TarFileDataFormat maxDecompressedSizeTar = new TarFileDataFormat();
+ // Only allow 10 bytes to be decompressed
+ maxDecompressedSizeTar.setMaxDecompressedSize(10L);
+ from("direct:untarMaxDecompressedSize").unmarshal(maxDecompressedSizeTar).to("mock:untar");
}
};
}
diff --git a/components/camel-zipfile/src/generated/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatConfigurer.java b/components/camel-zipfile/src/generated/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatConfigurer.java
index 72ea179..8f68fc1 100644
--- a/components/camel-zipfile/src/generated/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatConfigurer.java
+++ b/components/camel-zipfile/src/generated/java/org/apache/camel/dataformat/zipfile/ZipFileDataFormatConfigurer.java
@@ -24,6 +24,8 @@ public class ZipFileDataFormatConfigurer extends PropertyConfigurerSupport imple
case "allowEmptyDirectory": dataformat.setAllowEmptyDirectory(property(camelContext, boolean.class, value)); return true;
case "preservepathelements":
case "preservePathElements": dataformat.setPreservePathElements(property(camelContext, boolean.class, value)); return true;
+ case "maxdecompressedsize":
+ case "maxDecompressedSize": dataformat.setMaxDecompressedSize(property(camelContext, long.class, value)); return true;
default: return false;
}
}
diff --git a/components/camel-zipfile/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties b/components/camel-zipfile/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
index a7425ae..6ca22f8 100644
--- a/components/camel-zipfile/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
+++ b/components/camel-zipfile/src/generated/resources/META-INF/services/org/apache/camel/dataformat.properties
@@ -2,6 +2,6 @@
dataFormats=zipfile
groupId=org.apache.camel
artifactId=camel-zipfile
-version=3.4.4-SNAPSHOT
+version=3.4.5-SNAPSHOT
projectName=Camel :: Zip File
projectDescription=Camel Zip file support
diff --git a/components/camel-zipfile/src/generated/resources/org/apache/camel/dataformat/zipfile/zipfile.json b/components/camel-zipfile/src/generated/resources/org/apache/camel/dataformat/zipfile/zipfile.json
index 4f3ed26..a12099a 100644
--- a/components/camel-zipfile/src/generated/resources/org/apache/camel/dataformat/zipfile/zipfile.json
+++ b/components/camel-zipfile/src/generated/resources/org/apache/camel/dataformat/zipfile/zipfile.json
@@ -11,7 +11,7 @@
"supportLevel": "Stable",
"groupId": "org.apache.camel",
"artifactId": "camel-zipfile",
- "version": "3.4.4-SNAPSHOT",
+ "version": "3.4.5-SNAPSHOT",
"modelName": "zipfile",
"modelJavaType": "org.apache.camel.model.dataformat.ZipFileDataFormat"
},
@@ -19,6 +19,7 @@
"usingIterator": { "kind": "attribute", "displayName": "Using Iterator", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the zip file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode." },
"allowEmptyDirectory": { "kind": "attribute", "displayName": "Allow Empty Directory", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the zip file has more then one entry, setting this option to true, allows to get the iterator even if the directory is empty" },
"preservePathElements": { "kind": "attribute", "displayName": "Preserve Path Elements", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the file name contains path elements, setting this option to true, allows the path to be maintained in the zip file." },
+ "maxDecompressedSize": { "kind": "attribute", "displayName": "Max Decompressed Size", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "secret": false, "description": "Set the maximum decompressed size of a zip file (in bytes). An IOException will be thrown if the decompressed size exceeds this amount. Set to -1 to disable setting a maximum decompressed size. By default there is no maximum size enforced." },
"contentTypeHeader": { "kind": "attribute", "displayName": "Content Type Header", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshalling to JS [...]
"id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "The id of this node" }
}
diff --git a/components/camel-zipfile/src/main/docs/zipfile-dataformat.adoc b/components/camel-zipfile/src/main/docs/zipfile-dataformat.adoc
index 9a43e5d..3e49a3a 100644
--- a/components/camel-zipfile/src/main/docs/zipfile-dataformat.adoc
+++ b/components/camel-zipfile/src/main/docs/zipfile-dataformat.adoc
@@ -17,7 +17,7 @@ This data format supports ZIP64, as long as Java 7 or later is being used].
== ZipFile Options
// dataformat options: START
-The Zip File dataformat supports 4 options, which are listed below.
+The Zip File dataformat supports 5 options, which are listed below.
@@ -27,6 +27,7 @@ The Zip File dataformat supports 4 options, which are listed below.
| usingIterator | false | Boolean | If the zip file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode.
| allowEmptyDirectory | false | Boolean | If the zip file has more then one entry, setting this option to true, allows to get the iterator even if the directory is empty
| preservePathElements | false | Boolean | If the file name contains path elements, setting this option to true, allows the path to be maintained in the zip file.
+| maxDecompressedSize | | Long | Set the maximum decompressed size of a zip file (in bytes). An IOException will be thrown if the decompressed size exceeds this amount. Set to -1 to disable setting a maximum decompressed size. By default there is no maximum size enforced.
| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc.
|===
// dataformat options: END
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 f168642..b2c7531 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
@@ -46,6 +46,7 @@ public class ZipFileDataFormat extends ServiceSupport implements DataFormat, Dat
private boolean usingIterator;
private boolean allowEmptyDirectory;
private boolean preservePathElements;
+ private long maxDecompressedSize = -1;
@Override
public String getDataFormatName() {
@@ -97,7 +98,7 @@ public class ZipFileDataFormat extends ServiceSupport implements DataFormat, Dat
ZipEntry entry = zis.getNextEntry();
if (entry != null) {
exchange.getMessage().setHeader(FILE_NAME, entry.getName());
- IOHelper.copy(zis, osb);
+ IOHelper.copy(zis, osb, IOHelper.DEFAULT_BUFFER_SIZE, false, maxDecompressedSize);
} else {
throw new IllegalStateException("Unable to unzip the file, it may be corrupted.");
}
@@ -159,6 +160,14 @@ public class ZipFileDataFormat extends ServiceSupport implements DataFormat, Dat
this.preservePathElements = preservePathElements;
}
+ public long getMaxDecompressedSize() {
+ return maxDecompressedSize;
+ }
+
+ public void setMaxDecompressedSize(long maxDecompressedSize) {
+ this.maxDecompressedSize = maxDecompressedSize;
+ }
+
@Override
protected void doStart() throws Exception {
// noop
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 31115a0..dfb872e 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
@@ -245,6 +245,13 @@ public class ZipFileDataFormatTest extends CamelTestSupport {
assertMockEndpointsSatisfied();
}
+ @Test
+ public void testUnzipMaxDecompressedSize() throws Exception {
+ // We are only allowing 10 bytes to be decompressed, so we expect an error
+ assertThrows(CamelExecutionException.class,
+ () -> template.sendBody("direct:unzipMaxDecompressedSize", getZippedText("file")));
+ }
+
@Override
@Before
public void setUp() throws Exception {
@@ -316,6 +323,11 @@ public class ZipFileDataFormatTest extends CamelTestSupport {
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");
+
+ ZipFileDataFormat maxDecompressedSizeZip = new ZipFileDataFormat();
+ // Only allow 10 bytes to be decompressed
+ maxDecompressedSizeZip.setMaxDecompressedSize(10L);
+ from("direct:unzipMaxDecompressedSize").unmarshal(maxDecompressedSizeZip).to("mock:unzip");
}
};
}
diff --git a/core/camel-core-engine/src/generated/resources/org/apache/camel/model/dataformat/tarfile.json b/core/camel-core-engine/src/generated/resources/org/apache/camel/model/dataformat/tarfile.json
index c0a07c34..a5515d5 100644
--- a/core/camel-core-engine/src/generated/resources/org/apache/camel/model/dataformat/tarfile.json
+++ b/core/camel-core-engine/src/generated/resources/org/apache/camel/model/dataformat/tarfile.json
@@ -15,6 +15,7 @@
"usingIterator": { "kind": "attribute", "displayName": "Using Iterator", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the tar file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode." },
"allowEmptyDirectory": { "kind": "attribute", "displayName": "Allow Empty Directory", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the tar file has more then one entry, setting this option to true, allows to get the iterator even if the directory is empty" },
"preservePathElements": { "kind": "attribute", "displayName": "Preserve Path Elements", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the file name contains path elements, setting this option to true, allows the path to be maintained in the tar file." },
+ "maxDecompressedSize": { "kind": "attribute", "displayName": "Max Decompressed Size", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "secret": false, "description": "Set the maximum decompressed size of a tar file (in bytes). An IOException will be thrown if the decompressed size exceeds this amount. Set to -1 to disable setting a maximum decompressed size. By default there is no maximum size enforced." },
"contentTypeHeader": { "kind": "attribute", "displayName": "Content Type Header", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshalling to JS [...]
"id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "The id of this node" }
}
diff --git a/core/camel-core-engine/src/generated/resources/org/apache/camel/model/dataformat/zipfile.json b/core/camel-core-engine/src/generated/resources/org/apache/camel/model/dataformat/zipfile.json
index 279beb7..033577e 100644
--- a/core/camel-core-engine/src/generated/resources/org/apache/camel/model/dataformat/zipfile.json
+++ b/core/camel-core-engine/src/generated/resources/org/apache/camel/model/dataformat/zipfile.json
@@ -15,6 +15,7 @@
"usingIterator": { "kind": "attribute", "displayName": "Using Iterator", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the zip file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode." },
"allowEmptyDirectory": { "kind": "attribute", "displayName": "Allow Empty Directory", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the zip file has more then one entry, setting this option to true, allows to get the iterator even if the directory is empty" },
"preservePathElements": { "kind": "attribute", "displayName": "Preserve Path Elements", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "If the file name contains path elements, setting this option to true, allows the path to be maintained in the zip file." },
+ "maxDecompressedSize": { "kind": "attribute", "displayName": "Max Decompressed Size", "required": false, "type": "integer", "javaType": "java.lang.Long", "deprecated": false, "secret": false, "description": "Set the maximum decompressed size of a zip file (in bytes). An IOException will be thrown if the decompressed size exceeds this amount. Set to -1 to disable setting a maximum decompressed size. By default there is no maximum size enforced." },
"contentTypeHeader": { "kind": "attribute", "displayName": "Content Type Header", "required": false, "type": "boolean", "javaType": "java.lang.Boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application\/xml for data formats marshalling to XML, or application\/json for data formats marshalling to JS [...]
"id": { "kind": "attribute", "displayName": "Id", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "description": "The id of this node" }
}
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/model/dataformat/TarFileDataFormat.java b/core/camel-core-engine/src/main/java/org/apache/camel/model/dataformat/TarFileDataFormat.java
index 127547d..82aadff 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/model/dataformat/TarFileDataFormat.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/model/dataformat/TarFileDataFormat.java
@@ -40,6 +40,9 @@ public class TarFileDataFormat extends DataFormatDefinition {
@XmlAttribute
@Metadata(javaType = "java.lang.Boolean")
private String preservePathElements;
+ @XmlAttribute
+ @Metadata(javaType = "java.lang.Long")
+ private String maxDecompressedSize;
public TarFileDataFormat() {
super("tarfile");
@@ -57,6 +60,10 @@ public class TarFileDataFormat extends DataFormatDefinition {
return preservePathElements;
}
+ public String getMaxDecompressedSize() {
+ return maxDecompressedSize;
+ }
+
/**
* If the tar file has more then one entry, the setting this option to true,
* allows to work with the splitter EIP, to split the data using an iterator
@@ -81,4 +88,16 @@ public class TarFileDataFormat extends DataFormatDefinition {
public void setPreservePathElements(String preservePathElements) {
this.preservePathElements = preservePathElements;
}
+
+ /**
+ * Set the maximum decompressed size of a tar file (in bytes). An IOException will be thrown if the decompressed
+ * size exceeds this amount. Set to -1 to disable setting a maximum decompressed size. By default there is no
+ * maximum size enforced.
+ *
+ * @param maxDecompressedSize the maximum decompressed size of a tar file (in bytes)
+ */
+ public void setMaxDecompressedSize(String maxDecompressedSize) {
+ this.maxDecompressedSize = maxDecompressedSize;
+ }
+
}
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/model/dataformat/ZipFileDataFormat.java b/core/camel-core-engine/src/main/java/org/apache/camel/model/dataformat/ZipFileDataFormat.java
index 6889906..5b056fb 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/model/dataformat/ZipFileDataFormat.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/model/dataformat/ZipFileDataFormat.java
@@ -40,6 +40,9 @@ public class ZipFileDataFormat extends DataFormatDefinition {
@XmlAttribute
@Metadata(javaType = "java.lang.Boolean")
private String preservePathElements;
+ @XmlAttribute
+ @Metadata(javaType = "java.lang.Long")
+ private String maxDecompressedSize;
public ZipFileDataFormat() {
super("zipfile");
@@ -57,6 +60,10 @@ public class ZipFileDataFormat extends DataFormatDefinition {
return preservePathElements;
}
+ public String getMaxDecompressedSize() {
+ return maxDecompressedSize;
+ }
+
/**
* If the zip file has more then one entry, the setting this option to true,
* allows to work with the splitter EIP, to split the data using an iterator
@@ -82,4 +89,14 @@ public class ZipFileDataFormat extends DataFormatDefinition {
this.preservePathElements = preservePathElements;
}
+ /**
+ * Set the maximum decompressed size of a zip file (in bytes). An IOException will be thrown if the decompressed
+ * size exceeds this amount. Set to -1 to disable setting a maximum decompressed size. By default there is no
+ * maximum size enforced.
+ *
+ * @param maxDecompressedSize the maximum decompressed size of a zip file (in bytes)
+ */
+ public void setMaxDecompressedSize(String maxDecompressedSize) {
+ this.maxDecompressedSize = maxDecompressedSize;
+ }
}
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/TarFileDataFormatReifier.java b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/TarFileDataFormatReifier.java
index 6e5e3dc..4100def 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/TarFileDataFormatReifier.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/TarFileDataFormatReifier.java
@@ -32,6 +32,7 @@ public class TarFileDataFormatReifier extends DataFormatReifier<TarFileDataForma
protected void prepareDataFormatConfig(Map<String, Object> properties) {
properties.put("usingIterator", definition.getUsingIterator());
properties.put("preservePathElements", definition.getPreservePathElements());
+ properties.put("maxDecompressedSize", definition.getMaxDecompressedSize());
}
}
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/ZipFileDataFormatReifier.java b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/ZipFileDataFormatReifier.java
index 3f1042f..c49a7b7 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/ZipFileDataFormatReifier.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/reifier/dataformat/ZipFileDataFormatReifier.java
@@ -33,6 +33,7 @@ public class ZipFileDataFormatReifier extends DataFormatReifier<ZipFileDataForma
properties.put("usingIterator", definition.getUsingIterator());
properties.put("allowEmptyDirectory", definition.getAllowEmptyDirectory());
properties.put("preservePathElements", definition.getPreservePathElements());
+ properties.put("maxDecompressedSize", definition.getMaxDecompressedSize());
}
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
index aec5a9f..fb3cc49 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/IOHelper.java
@@ -154,7 +154,16 @@ public final class IOHelper {
return copy(input, output, bufferSize, false);
}
- public static int copy(final InputStream input, final OutputStream output, int bufferSize, boolean flushOnEachWrite) throws IOException {
+ public static int copy(final InputStream input, final OutputStream output, int bufferSize, boolean flushOnEachWrite)
+ throws IOException {
+ return copy(input, output, bufferSize, flushOnEachWrite, -1);
+ }
+
+ public static int copy(
+ final InputStream input, final OutputStream output, int bufferSize, boolean flushOnEachWrite,
+ long maxSize)
+ throws IOException {
+
if (input instanceof ByteArrayInputStream) {
// optimized for byte array as we only need the max size it can be
input.mark(0);
@@ -196,6 +205,9 @@ public final class IOHelper {
output.flush();
}
total += n;
+ if (maxSize > 0 && total > maxSize) {
+ throw new IOException("The InputStream entry being copied exceeds the maximum allowed size");
+ }
n = input.read(buffer);
}
}
diff --git a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
index b73f673..b90b0b9 100644
--- a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
+++ b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
@@ -2072,6 +2072,7 @@ public class ModelParser extends BaseParser {
return doParse(new TarFileDataFormat(), (def, key, val) -> {
switch (key) {
case "allowEmptyDirectory": def.setAllowEmptyDirectory(val); break;
+ case "maxDecompressedSize": def.setMaxDecompressedSize(val); break;
case "preservePathElements": def.setPreservePathElements(val); break;
case "usingIterator": def.setUsingIterator(val); break;
default: return dataFormatDefinitionAttributeHandler().accept(def, key, val);
@@ -2269,6 +2270,7 @@ public class ModelParser extends BaseParser {
return doParse(new ZipFileDataFormat(), (def, key, val) -> {
switch (key) {
case "allowEmptyDirectory": def.setAllowEmptyDirectory(val); break;
+ case "maxDecompressedSize": def.setMaxDecompressedSize(val); break;
case "preservePathElements": def.setPreservePathElements(val); break;
case "usingIterator": def.setUsingIterator(val); break;
default: return dataFormatDefinitionAttributeHandler().accept(def, key, val);
diff --git a/docs/components/modules/dataformats/pages/tarfile-dataformat.adoc b/docs/components/modules/dataformats/pages/tarfile-dataformat.adoc
index aff160a..f712211 100644
--- a/docs/components/modules/dataformats/pages/tarfile-dataformat.adoc
+++ b/docs/components/modules/dataformats/pages/tarfile-dataformat.adoc
@@ -22,7 +22,7 @@ aggregate multiple messages into a single Tar File.
// dataformat options: START
-The Tar File dataformat supports 4 options, which are listed below.
+The Tar File dataformat supports 5 options, which are listed below.
@@ -32,6 +32,7 @@ The Tar File dataformat supports 4 options, which are listed below.
| usingIterator | false | Boolean | If the tar file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode.
| allowEmptyDirectory | false | Boolean | If the tar file has more then one entry, setting this option to true, allows to get the iterator even if the directory is empty
| preservePathElements | false | Boolean | If the file name contains path elements, setting this option to true, allows the path to be maintained in the tar file.
+| maxDecompressedSize | 1073741824L | Long | Set the maximum decompressed size of a tar file (in bytes). The default value if not specified corresponds to 1 gigabyte. An IOException will be thrown if the decompressed size exceeds this amount. Set to -1 to disable setting a maximum decompressed size.
| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc.
|===
// dataformat options: END
diff --git a/docs/components/modules/dataformats/pages/zipfile-dataformat.adoc b/docs/components/modules/dataformats/pages/zipfile-dataformat.adoc
index a683a84..ab57012 100644
--- a/docs/components/modules/dataformats/pages/zipfile-dataformat.adoc
+++ b/docs/components/modules/dataformats/pages/zipfile-dataformat.adoc
@@ -19,7 +19,7 @@ This data format supports ZIP64, as long as Java 7 or later is being used].
== ZipFile Options
// dataformat options: START
-The Zip File dataformat supports 4 options, which are listed below.
+The Zip File dataformat supports 5 options, which are listed below.
@@ -29,6 +29,7 @@ The Zip File dataformat supports 4 options, which are listed below.
| usingIterator | false | Boolean | If the zip file has more then one entry, the setting this option to true, allows to work with the splitter EIP, to split the data using an iterator in a streaming mode.
| allowEmptyDirectory | false | Boolean | If the zip file has more then one entry, setting this option to true, allows to get the iterator even if the directory is empty
| preservePathElements | false | Boolean | If the file name contains path elements, setting this option to true, allows the path to be maintained in the zip file.
+| maxDecompressedSize | 1073741824L | Long | Set the maximum decompressed size of a zip file (in bytes). The default value if not specified corresponds to 1 gigabyte. An IOException will be thrown if the decompressed size exceeds this amount. Set to -1 to disable setting a maximum decompressed size.
| contentTypeHeader | false | Boolean | Whether the data format should set the Content-Type header with the type from the data format if the data format is capable of doing so. For example application/xml for data formats marshalling to XML, or application/json for data formats marshalling to JSON etc.
|===
// dataformat options: END