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

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 42689cd0e6 [hotfix] Catch NegativeArraySizeException when reserveBytes 
in HeapBytesVector (#5275)
42689cd0e6 is described below

commit 42689cd0e658064a545c2d16afbf4bbdc80be891
Author: xiangyu0xf <[email protected]>
AuthorDate: Thu Mar 13 12:06:54 2025 +0800

    [hotfix] Catch NegativeArraySizeException when reserveBytes in 
HeapBytesVector (#5275)
---
 .../apache/paimon/data/columnar/heap/HeapBytesVector.java   | 11 ++++++++++-
 .../parquet/newreader/DeltaByteArrayEncodingTest.java       | 13 +++++++++++++
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git 
a/paimon-common/src/main/java/org/apache/paimon/data/columnar/heap/HeapBytesVector.java
 
b/paimon-common/src/main/java/org/apache/paimon/data/columnar/heap/HeapBytesVector.java
index c4e6592e10..3320ee7f4f 100644
--- 
a/paimon-common/src/main/java/org/apache/paimon/data/columnar/heap/HeapBytesVector.java
+++ 
b/paimon-common/src/main/java/org/apache/paimon/data/columnar/heap/HeapBytesVector.java
@@ -102,7 +102,16 @@ public class HeapBytesVector extends AbstractHeapVector 
implements WritableBytes
     private void reserveBytes(int newCapacity) {
         if (newCapacity > buffer.length) {
             int newBytesCapacity = newCapacity * 2;
-            buffer = Arrays.copyOf(buffer, newBytesCapacity);
+            try {
+                buffer = Arrays.copyOf(buffer, newBytesCapacity);
+            } catch (NegativeArraySizeException e) {
+                throw new RuntimeException(
+                        String.format(
+                                "The new claimed capacity %s is too large, 
will overflow the INTEGER.MAX after multiply by 2. "
+                                        + "Try reduce `read.batch-size` to 
avoid this exception.",
+                                newCapacity),
+                        e);
+            }
         }
     }
 
diff --git 
a/paimon-format/src/test/java/org/apache/paimon/format/parquet/newreader/DeltaByteArrayEncodingTest.java
 
b/paimon-format/src/test/java/org/apache/paimon/format/parquet/newreader/DeltaByteArrayEncodingTest.java
index 60d915ccfa..84818dd01b 100644
--- 
a/paimon-format/src/test/java/org/apache/paimon/format/parquet/newreader/DeltaByteArrayEncodingTest.java
+++ 
b/paimon-format/src/test/java/org/apache/paimon/format/parquet/newreader/DeltaByteArrayEncodingTest.java
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.Test;
 
 import static org.junit.jupiter.api.Assertions.assertArrayEquals;
 import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 /* This file is based on source code from the Spark Project 
(http://spark.apache.org/), licensed by the Apache
  * Software Foundation (ASF) under the Apache License, Version 2.0. See the 
NOTICE file distributed with this work for
@@ -93,6 +94,18 @@ public class DeltaByteArrayEncodingTest {
         assertEquals(7, writableColumnVector.getInt(2));
     }
 
+    @Test
+    public void testNegativeSize() {
+        HeapBytesVector heapBytesVector = new HeapBytesVector(32);
+        assertThrows(
+                RuntimeException.class,
+                () -> heapBytesVector.putByteArray(1, null, 0, 
Integer.MAX_VALUE - 1),
+                String.format(
+                        "The new claimed capacity %s is too large, will 
overflow the INTEGER.MAX after multiply by 2. "
+                                + "Try reduce `read.batch-size` to avoid this 
exception.",
+                        Integer.MAX_VALUE - 1));
+    }
+
     private void assertReadWrite(
             DeltaByteArrayWriter writer, VectorizedDeltaByteArrayReader 
reader, String[] vals)
             throws Exception {

Reply via email to