This is an automated email from the ASF dual-hosted git repository.
andor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/master by this push:
new dcaf74c36 ZOOKEEPER-4843: Encountering an 'Unreasonable Length' error
when configuring jute.maxbuffer to 1GB or more
dcaf74c36 is described below
commit dcaf74c369222a82000ea07a1e5953ca91782084
Author: Mohammad Arshad <[email protected]>
AuthorDate: Fri Sep 20 23:45:11 2024 +0530
ZOOKEEPER-4843: Encountering an 'Unreasonable Length' error when
configuring jute.maxbuffer to 1GB or more
Reviewers: anmolnar, kezhuw
Author: arshadmohammad
Closes #2175 from arshadmohammad/totalBuffer
---
.../src/main/java/org/apache/jute/BinaryInputArchive.java | 12 +++++++-----
.../test/java/org/apache/jute/BinaryInputArchiveTest.java | 13 +++++++++++++
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git
a/zookeeper-jute/src/main/java/org/apache/jute/BinaryInputArchive.java
b/zookeeper-jute/src/main/java/org/apache/jute/BinaryInputArchive.java
index ae1310af0..277faf489 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/BinaryInputArchive.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/BinaryInputArchive.java
@@ -48,8 +48,7 @@ public class BinaryInputArchive implements InputArchive {
}
private final DataInput in;
- private final int maxBufferSize;
- private final int extraMaxBufferSize;
+ private final int totalBufferSize;
public static BinaryInputArchive getArchive(InputStream stream) {
return new BinaryInputArchive(new DataInputStream(stream));
@@ -80,8 +79,11 @@ public class BinaryInputArchive implements InputArchive {
public BinaryInputArchive(DataInput in, int maxBufferSize, int
extraMaxBufferSize) {
this.in = in;
- this.maxBufferSize = maxBufferSize;
- this.extraMaxBufferSize = extraMaxBufferSize;
+ if ((long) maxBufferSize + extraMaxBufferSize > Integer.MAX_VALUE) {
+ this.totalBufferSize = Integer.MAX_VALUE;
+ } else {
+ this.totalBufferSize = maxBufferSize + extraMaxBufferSize;
+ }
}
public byte readByte(String tag) throws IOException {
@@ -162,7 +164,7 @@ public class BinaryInputArchive implements InputArchive {
// make up for extra fields, etc. (otherwise e.g. clients may be able to
// write buffers larger than we can read from disk!)
private void checkLength(int len) throws IOException {
- if (len < 0 || len > maxBufferSize + extraMaxBufferSize) {
+ if (len < 0 || len > totalBufferSize) {
throw new IOException(UNREASONBLE_LENGTH + len);
}
}
diff --git
a/zookeeper-jute/src/test/java/org/apache/jute/BinaryInputArchiveTest.java
b/zookeeper-jute/src/test/java/org/apache/jute/BinaryInputArchiveTest.java
index 9a1c70eeb..294a8b129 100644
--- a/zookeeper-jute/src/test/java/org/apache/jute/BinaryInputArchiveTest.java
+++ b/zookeeper-jute/src/test/java/org/apache/jute/BinaryInputArchiveTest.java
@@ -195,4 +195,17 @@ public class BinaryInputArchiveTest {
return buf.array();
}
+ @Test
+ public void testTotalBufferSizeShouldNotBeMoreThanIntegerMaxValue()
+ throws IOException {
+ int maxBufferSize = 1 * 1024 * 1024 * 1024; // buffer size 1GB
+ int extraMaxBufferSize = maxBufferSize;
+ int recordSize = 1000;
+ BinaryInputArchive ia =
+ getBinaryInputArchive(recordSize, maxBufferSize,
extraMaxBufferSize);
+ String s = ia.readString("");
+ assertNotNull(s);
+ assertEquals(recordSize, s.getBytes().length);
+ }
+
}