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

davsclaus pushed a commit to branch camel-4.0.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.0.x by this push:
     new 7029d87bfc8 CAMEL-19975: Convert file to ByteBuffer should fail if the 
file is too large
7029d87bfc8 is described below

commit 7029d87bfc8d6bbbb6192808f5f0004fcf294ddc
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Sat Oct 21 13:29:58 2023 +0200

    CAMEL-19975: Convert file to ByteBuffer should fail if the file is too large
---
 .../src/main/java/org/apache/camel/converter/NIOConverter.java     | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git 
a/core/camel-base/src/main/java/org/apache/camel/converter/NIOConverter.java 
b/core/camel-base/src/main/java/org/apache/camel/converter/NIOConverter.java
index 8d3aed054dd..91080749d9d 100644
--- a/core/camel-base/src/main/java/org/apache/camel/converter/NIOConverter.java
+++ b/core/camel-base/src/main/java/org/apache/camel/converter/NIOConverter.java
@@ -71,6 +71,13 @@ public final class NIOConverter {
 
     @Converter(order = 5)
     public static ByteBuffer toByteBuffer(File file) throws IOException {
+        if (file.length() > Integer.MAX_VALUE) {
+            // very big file we cannot load into memory
+            throw new IOException(
+                    "Cannot convert file: " + file.getName() + " to 
ByteBuffer. The file length is too large: "
+                                  + file.length());
+        }
+
         InputStream in = null;
         try {
             byte[] buf = new byte[(int) file.length()];

Reply via email to