This is an automated email from the ASF dual-hosted git repository.
gangwu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/parquet-mr.git
The following commit(s) were added to refs/heads/master by this push:
new 72442b5c5 PARQUET-2164: Check size of buffered data to prevent page
data from overflowing (#1032)
72442b5c5 is described below
commit 72442b5c5cbf4bf20258dd22432a5c39081193fc
Author: Parth Chandra <[email protected]>
AuthorDate: Sat Mar 11 06:06:57 2023 -0800
PARQUET-2164: Check size of buffered data to prevent page data from
overflowing (#1032)
- Use Math.addExact to detect overflow
---
.../org/apache/parquet/bytes/CapacityByteArrayOutputStream.java | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git
a/parquet-common/src/main/java/org/apache/parquet/bytes/CapacityByteArrayOutputStream.java
b/parquet-common/src/main/java/org/apache/parquet/bytes/CapacityByteArrayOutputStream.java
index 39b2863e9..305a28769 100644
---
a/parquet-common/src/main/java/org/apache/parquet/bytes/CapacityByteArrayOutputStream.java
+++
b/parquet-common/src/main/java/org/apache/parquet/bytes/CapacityByteArrayOutputStream.java
@@ -164,6 +164,15 @@ public class CapacityByteArrayOutputStream extends
OutputStream {
private void addSlab(int minimumSize) {
int nextSlabSize;
+ // check for overflow
+ try {
+ Math.addExact(bytesUsed, minimumSize);
+ } catch (ArithmeticException e) {
+ // This is interpreted as a request for a value greater than
Integer.MAX_VALUE
+ // We throw OOM because that is what java.io.ByteArrayOutputStream also
does
+ throw new OutOfMemoryError("Size of data exceeded Integer.MAX_VALUE (" +
e.getMessage() + ")");
+ }
+
if (bytesUsed == 0) {
nextSlabSize = initialSlabSize;
} else if (bytesUsed > maxCapacityHint / 5) {