Skip to content

Commit daa958c

Browse files
committed
fix out-of-slice read in ArrowFlightJdbcArray.checkBoundaries
1 parent 7f1f9f5 commit daa958c

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

flight/flight-sql-jdbc-core/src/main/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArray.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public Object getArray(long index, int count) throws SQLException {
9090
}
9191

9292
private void checkBoundaries(long index, int count) {
93-
if (index < 0 || index + count > this.startOffset + this.valuesCount) {
93+
if (index < 0 || index + count > this.valuesCount) {
9494
throw new ArrayIndexOutOfBoundsException();
9595
}
9696
}

flight/flight-sql-jdbc-core/src/test/java/org/apache/arrow/driver/jdbc/ArrowFlightJdbcArrayTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ public void testShouldGetArrayWithOffsetsThrowArrayIndexOutOfBoundsException()
105105
() -> arrowFlightJdbcArray.getArray(0, dataVector.getValueCount() + 1));
106106
}
107107

108+
@Test
109+
public void testShouldGetArrayWithOffsetsNotReadPastEndOfSlice() throws SQLException {
110+
// Array covering elements 5, 6 and 7 of the underlying vector.
111+
ArrowFlightJdbcArray arrowFlightJdbcArray = new ArrowFlightJdbcArray(dataVector, 5, 3);
112+
assertThrows(ArrayIndexOutOfBoundsException.class, () -> arrowFlightJdbcArray.getArray(1, 3));
113+
}
114+
115+
@Test
116+
public void testShouldGetResultSetWithOffsetsNotReadPastEndOfSlice() throws SQLException {
117+
ArrowFlightJdbcArray arrowFlightJdbcArray = new ArrowFlightJdbcArray(dataVector, 5, 3);
118+
assertThrows(
119+
ArrayIndexOutOfBoundsException.class, () -> arrowFlightJdbcArray.getResultSet(1, 3));
120+
}
121+
108122
@Test
109123
public void testShouldGetArrayWithMapNotBeSupported() throws SQLException {
110124
ArrowFlightJdbcArray arrowFlightJdbcArray =

0 commit comments

Comments
 (0)