The IPC reader accepts a column that is shorter than its RecordBatch, and fills the missing rows with nulls
Los mantenedores suelen responder en 1 dí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
- Activo
- Stack tecnológico
- typescript
- Área
- backend
Línea de trabajo
Empieza con _loadRecordBatch() en src/ipc/reader.ts y sigue cómo las longitudes de los nodos de campo llegan al constructor de RecordBatch en src/recordbatch.ts. La reproducción del issue muestra la discrepancia para las longitudes 2 y 0 en un batch de 4; ejecútala con ambos casos. El trabajo estará terminado cuando cada flujo malformado genere un error en lugar de rellenar las filas que faltan con valores null.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug, including details regarding any error messages, version, and platform.
The IPC reader does not compare the length of each field node with the length of its RecordBatch. A column that declares fewer rows than its batch reads with no error. The table keeps the row count of the batch, the reader fills the rows past the length of the column with nulls, and the field of the column becomes nullable.
The repro changes one valid stream of x: [10, 20, 30, 40] and y: [1, 2, 3, 4] (Int32, 4 rows) in two ways:
- The field node of
xdeclares 2 rows.xreads as[10, 20, null, null]. - The field node of
xdeclares 0 rows.xreads as[null, null, null, null].
The writer did not write these nulls, and a reader cannot tell them from real nulls. In Arrow C++, RecordBatch::Validate() refuses a column whose length is not the row count of the batch.
The open PR #551 checks the buffer regions against the message body. The buffers of these streams do not change, so the two reads also give no error with the change of #551. This fault is not the same as the second case of #548: there, the field node declares more rows than the buffers hold. Here, the buffers are correct and the field node declares fewer rows than the batch.
Version and platform: apache-arrow 21.2.0, Node.js 24.21.0 on Windows 11. The code below is the same on main (f547423).
Repro. Save as repro.ts, install [email protected], and run node repro.ts (Node.js 24 strips the types). It exits 1 while the fault is present.
// apache-arrow 21.2.0. The IPC reader does not compare the length of each field node with the length of its
// RecordBatch. A column that declares fewer rows than its batch reads with no error: the table keeps the row count of
// the batch, and the reader fills the rows past the length of the column with nulls.
import * as A from "apache-arrow";
const table = new A.Table({
x: A.vectorFromArray([10, 20, 30, 40], new A.Int32()),
y: A.vectorFromArray([1, 2, 3, 4], new A.Int32()),
});
const valid = A.tableToIPC(table, "stream");
// The field nodes of the batch are [{ length: 4, nullCount: 0 }, { length: 4, nullCount: 0 }], as little-endian int64 values.
const nodes = new Uint8Array(new BigInt64Array([4n, 0n, 4n, 0n]).buffer);
/** This function gives the one place of `pattern` in `bytes`. */
function placeOf(bytes: Uint8Array, pattern: Uint8Array): number {
const places: number[] = [];
for (let at = 0; at + pattern.length <= bytes.length; at += 1) {
if (pattern.every((byte, index) => bytes[at + index] === byte)) places.push(at);
}
if (places.length !== 1) throw new Error(`expected 1 place of the field nodes, found ${places.length}`);
return places[0]!;
}
/** This function gives a copy of the valid stream in which the field node of x declares `length` rows. */
function withLengthOfX(length: number): Uint8Array {
const copy = valid.slice();
new DataView(copy.buffer, copy.byteOffset).setBigInt64(placeOf(copy, nodes), BigInt(length), true);
return copy;
}
let faults = 0;
for (const length of [2, 0]) {
try {
const read = A.tableFromIPC(withLengthOfX(length));
const x = read.getChild("x");
console.log(`x declares ${length} rows in a batch of 4: no error, numRows ${read.numRows}, x.get(i) = [${Array.from({ length: read.numRows }, (_, i) => String(x?.get(i))).join(", ")}], x.length ${x?.length}`);
faults += 1;
} catch (error) {
console.log(`x declares ${length} rows in a batch of 4: ${String(error)}`);
}
}
process.exit(faults > 0 ? 1 : 0);
Output:
x declares 2 rows in a batch of 4: no error, numRows 4, x.get(i) = [10, 20, null, null], x.length 4
x declares 0 rows in a batch of 4: no error, numRows 4, x.get(i) = [null, null, null, null], x.length 4
exit code: 1
Expected: An error for each of the two streams. The field node of each column of a RecordBatch must declare the length of the batch.
Cause: _loadRecordBatch() in src/ipc/reader.ts (lines 378 to 382) loads the columns with the lengths of their field nodes and gives them to the RecordBatch constructor with header.length. The constructor calls ensureSameLengthData() in src/recordbatch.ts (line 318). For each column that is shorter than the batch, this function makes the field nullable and fills the missing rows with nulls (_changeLengthAndBackfillNullBitmap). This is correct when a program makes a table from columns of different lengths, but it hides the fault in IPC data.
Possible fix: In _loadRecordBatch(), throw an error when the length of a column is not header.length, before the RecordBatch constructor runs.
An AI coding assistant (Claude Code) found this fault, wrote the repro and wrote this text.
Component(s)
JavaScript
- Lenguaje dominante
- TypeScript
- Estrellas
- 114
- Forks
- 35
- Merge medio
- 13 h 35 min
- PR fusionados (30 d)
- 5
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apache/arrow-js
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
The IPC reader ignores Schema.endianness: a big-endian stream reads 1, 2, 3 as 16777216, 33554432, 50331648Posiblemente ocupada @aniket-r2Dev2 la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
tableFromIPC loops with no end on a file whose RecordBatch block points at a DictionaryBatchPosiblemente ocupada @aniket-r2Dev2 la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
apache/arrow-js#547 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
The stream reader drops a message of an unexpected type but not its body, and parses the body as the next messagesPosiblemente ocupada @Umer-Butt07 la tomó hace 3 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
Los mantenedores suelen responder en 1 día
-
The file reader accepts two non-delta DictionaryBatches for one id, and the column values change with no errorPosiblemente ocupada @Sealdot la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
Todos los issues de apache/arrow-js
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 74/100
juspay/odu#193 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Add: Alfa DramasAbiertocheck:passed streams:add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
ready-for-agent
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Maduki-tech/bautackt#4 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
moq-dev/moq#10463 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día