ArrowFlightJdbcArray.getArray(index, count) can read past the end of the array slice

Abierto Apto para principiantes
#1,236 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
java
Área
database

Línea de trabajo

Comienza en ArrowFlightJdbcArray.checkBoundaries e inspecciona los puntos de llamada de getArray(index, count) y getResultSet(index, count). Añade una prueba de regresión usando un startOffset distinto de cero, como el slice de IntVector proporcionado, y ejecuta las pruebas existentes de ArrowFlightJdbcArray; se considera terminado cuando las solicitudes no pueden leer más allá del slice del array.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

ArrowFlightJdbcArray.checkBoundaries validates the caller-supplied index against startOffset + valuesCount:

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

but index is relative to the start of the array; both call sites add startOffset to it only afterwards, e.g.

checkBoundaries(index, count);
return getArrayNoBoundCheck(
    this.dataVector, LargeMemoryUtil.checkedCastToInt(this.startOffset + index), count);

So the accepted range is too large by exactly startOffset elements, and getArray(index, count) / getResultSet(index, count) will read up to that far past the end of the row's slice.

AbstractArrowFlightJdbcListVectorAccessor builds these with the offsets of the list element being read, so any row of a list column that does not start at child offset 0 is affected. Reading within the element count the driver itself advertises then returns values belonging to other rows of the shared child vector, and past the child vector's valueCount it returns whatever is in allocated-but-unwritten memory.

Reproducer against an IntVector of 127 values, with an array covering elements 5..7:

ArrowFlightJdbcArray array = new ArrowFlightJdbcArray(dataVector, 5, 3);
array.getArray(1, 3); // accepted; returns elements 6, 7, 8 — element 8 is outside the array

Every existing test constructs the array with startOffset 0, where the wrong bound happens to coincide with the correct one, which is why this is not currently caught.

Lenguaje dominante
Java
Estrellas
95
Forks
154
Merge medio
2 d 16 h
PR fusionados (30 d)
9

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de apache/arrow-java

Todos los issues de apache/arrow-java

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.