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

jbonofre pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-java.git


The following commit(s) were added to refs/heads/main by this push:
     new 64c8fda33 GH-1236: fix out-of-slice read in 
ArrowFlightJdbcArray.checkBoundaries (#1237)
64c8fda33 is described below

commit 64c8fda33b1af68348a140003604e3ebc79771d6
Author: Abdul Rawoof Khan <[email protected]>
AuthorDate: Tue Nov 17 09:34:57 2026 +0530

    GH-1236: fix out-of-slice read in ArrowFlightJdbcArray.checkBoundaries 
(#1237)
    
    ## What's Changed
    
    checkBoundaries validates the caller index against startOffset +
    valuesCount, but index is relative to the start of the array and both
    call sites add startOffset to it only after the check, so the accepted
    range is too long by exactly startOffset elements. getArray and
    getResultSet then read that far past the end of the row's slice.
    AbstractArrowFlightJdbcListVectorAccessor constructs these from the
    offsets of the list element being read, so any row of a list column not
    starting at child offset 0 hands back values belonging to neighbouring
    rows of the shared child vector, and past the child's valueCount
    whatever is in allocated-but-unwritten memory. The bound belongs on the
    relative index, so it is compared against valuesCount instead; that is
    the same expression as today when startOffset is 0, which is why the
    existing tests all pass unchanged and only the offset case gets tighter.
    Added a regression test for each of the two entry points, both of which
    fail on main.
    
    Closes #1236.
---
 .../org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java |  2 +-
 .../apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git 
a/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java
 
b/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java
index f3d76ace9..b916f78b1 100644
--- 
a/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java
+++ 
b/flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java
@@ -90,7 +90,7 @@ public class ArrowFlightJdbcArray implements Array {
   }
 
   private void checkBoundaries(long index, int count) {
-    if (index < 0 || index + count > this.startOffset + this.valuesCount) {
+    if (index < 0 || index + count > this.valuesCount) {
       throw new ArrayIndexOutOfBoundsException();
     }
   }
diff --git 
a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java
 
b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java
index cb6abacb2..090a026b8 100644
--- 
a/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java
+++ 
b/flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java
@@ -105,6 +105,20 @@ public class ArrowFlightJdbcArrayTest {
         () -> arrowFlightJdbcArray.getArray(0, dataVector.getValueCount() + 
1));
   }
 
+  @Test
+  public void testShouldGetArrayWithOffsetsNotReadPastEndOfSlice() throws 
SQLException {
+    // Array covering elements 5, 6 and 7 of the underlying vector.
+    ArrowFlightJdbcArray arrowFlightJdbcArray = new 
ArrowFlightJdbcArray(dataVector, 5, 3);
+    assertThrows(ArrayIndexOutOfBoundsException.class, () -> 
arrowFlightJdbcArray.getArray(1, 3));
+  }
+
+  @Test
+  public void testShouldGetResultSetWithOffsetsNotReadPastEndOfSlice() throws 
SQLException {
+    ArrowFlightJdbcArray arrowFlightJdbcArray = new 
ArrowFlightJdbcArray(dataVector, 5, 3);
+    assertThrows(
+        ArrayIndexOutOfBoundsException.class, () -> 
arrowFlightJdbcArray.getResultSet(1, 3));
+  }
+
   @Test
   public void testShouldGetArrayWithMapNotBeSupported() throws SQLException {
     ArrowFlightJdbcArray arrowFlightJdbcArray =

Reply via email to