aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-02-19 20:50:51 +0000
committerPJ Fanning <fanningpj@apache.org>2022-02-19 20:50:51 +0000
commita02df8a2c81b2fff5e7fe73fb97ed13aa021eb96 (patch)
tree187408d1e29f292ca4fdbe1dc3f0a43b12e46062
parent8e9496a475b43c94e8c9ad37396a89fecd00902c (diff)
downloadpoi-a02df8a2c81b2fff5e7fe73fb97ed13aa021eb96.tar.gz
poi-a02df8a2c81b2fff5e7fe73fb97ed13aa021eb96.zip
[bug-65639] take BYTE_ARRAY_MAX_OVERRIDE into account in IOUtils#toByteArray
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1898231 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi/src/main/java/org/apache/poi/util/IOUtils.java11
1 files changed, 8 insertions, 3 deletions
diff --git a/poi/src/main/java/org/apache/poi/util/IOUtils.java b/poi/src/main/java/org/apache/poi/util/IOUtils.java
index d508833464..fa4cb785bd 100644
--- a/poi/src/main/java/org/apache/poi/util/IOUtils.java
+++ b/poi/src/main/java/org/apache/poi/util/IOUtils.java
@@ -96,6 +96,10 @@ public final class IOUtils {
}
}
+ private static int getByteArrayLimit() {
+ return BYTE_ARRAY_MAX_OVERRIDE < 0 ? Integer.MAX_VALUE : BYTE_ARRAY_MAX_OVERRIDE;
+ }
+
/**
* Peeks at the first N bytes of the stream. Returns those bytes, but
* with the stream unaffected. Requires a stream that supports mark/reset,
@@ -130,14 +134,15 @@ public final class IOUtils {
}
/**
- * Reads all the data from the input stream, and returns the bytes read.
+ * Reads all the data from the input stream, and returns the bytes read. If {@link #setByteArrayMaxOverride(int)}
+ * is used then that limit is applied and this call will fail if the array size exceeds the configured limit.
*
* @param stream The byte stream of data to read.
* @return A byte array with the read bytes.
* @throws IOException If reading data fails or EOF is encountered too early for the given length.
*/
public static byte[] toByteArray(InputStream stream) throws IOException {
- return toByteArray(stream, Integer.MAX_VALUE);
+ return toByteArray(stream, getByteArrayLimit());
}
/**
@@ -150,7 +155,7 @@ public final class IOUtils {
* @throws IOException If reading data fails or EOF is encountered too early for the given length.
*/
public static byte[] toByteArray(InputStream stream, final int length) throws IOException {
- return toByteArray(stream, length, Integer.MAX_VALUE);
+ return toByteArray(stream, length, getByteArrayLimit());
}