The IPC reader ignores Schema.endianness: a big-endian stream reads 1, 2, 3 as 16777216, 33554432, 50331648
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 82/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- javascript, typescript
- Domaine
- data
Piste de recherche
Commence à decodeSchema() dans src/ipc/metadata/message.ts (lignes 351-354), où les champs et les métadonnées personnalisées sont lus mais _schema.endianness() ne l'est pas. Donne à la classe Schema un champ d'endianness, puis soit lève une erreur nommée à cet endroit, soit transmets-le au chargeur de record batch pour faire un byte-swap des tampons de largeur fixe. Terminé signifie que repro.ts de l'issue se termine avec 0, en affichant [1,2,3] ou une erreur d'endianness, plus un test à côté des tests existants du lecteur IPC.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug, including details regarding any error messages, version, and platform.
The IPC reader ignores Schema.endianness. A stream whose schema says Big, with its values in big-endian byte order, reads as little endian, with no byte swap and no error. The repro makes such a stream of the int32 values [1, 2, 3], as a big-endian producer writes it. tableFromIPC returns [16777216, 33554432, 50331648].
The format lets a reader byte-swap such data or refuse it. Arrow C++ byte-swaps it by default (IpcReadOptions::ensure_native_endian in cpp/src/arrow/ipc/options.h), so Arrow C++ and Arrow JS give different values for the same bytes. The Arrow JS writer itself writes Endianness.Big on a big-endian platform (src/ipc/metadata/message.ts line 607), so a stream from Arrow JS on such a platform also reads wrong on a little-endian platform.
Version and platform: apache-arrow 21.2.0, Node.js 24.21.0 on Windows 11. The code below is the same on main (5aa0205).
Repro. Save as repro.ts, install [email protected] and [email protected] (the version that apache-arrow installs), 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 reader ignores Schema.endianness. decodeSchema() does not read the field, so a stream from
// a big-endian producer (Schema.endianness = Big, values in big-endian byte order) reads as little endian, with no
// error and no byte swap. The int32 values 1, 2 and 3 read as 16777216, 33554432 and 50331648.
import * as A from "apache-arrow";
import { Message } from "apache-arrow/fb/message";
import { Schema } from "apache-arrow/fb/schema";
import * as flatbuffers from "flatbuffers";
const values = Int32Array.of(1, 2, 3);
const stream = A.tableToIPC(A.tableFromArrays({ x: values }), "stream");
// The Schema message is first and has no body. The RecordBatch message follows, then the end-of-stream marker.
const view = new DataView(stream.buffer, stream.byteOffset, stream.byteLength);
const batchStart = 8 + view.getInt32(4, true);
const batchMetadataLength = view.getInt32(batchStart + 4, true);
const batchBodyStart = batchStart + 8 + batchMetadataLength;
const batchBodyLength = Number(A.Message.decode(stream.subarray(batchStart + 8, batchBodyStart)).bodyLength);
const batchEnd = batchBodyStart + batchBodyLength;
// A Schema message with the same fields and Schema.endianness = Big (1), as a big-endian producer writes it. The
// little-endian writer leaves out the field (Little is the default), so there is no byte to change.
const builder = new flatbuffers.Builder(256);
const schema = A.tableFromIPC(stream).schema;
const fields = Schema.createFieldsVector(builder, schema.fields.map((field) => (A.Field as any).encode(builder, field)));
Schema.startSchema(builder);
Schema.addFields(builder, fields);
Schema.addEndianness(builder, 1);
const schemaOffset = Schema.endSchema(builder);
Message.startMessage(builder);
Message.addVersion(builder, A.MetadataVersion.V5);
Message.addHeaderType(builder, A.MessageHeader.Schema);
Message.addHeader(builder, schemaOffset);
Message.addBodyLength(builder, 0n);
Message.finishMessageBuffer(builder, Message.endMessage(builder));
const flatbuffer = builder.asUint8Array();
const metadata = new Uint8Array(Math.ceil((flatbuffer.length + 8) / 8) * 8 - 8);
metadata.set(flatbuffer);
const bigEndianSchema = new Uint8Array(8 + metadata.length);
new DataView(bigEndianSchema.buffer).setInt32(0, -1, true);
new DataView(bigEndianSchema.buffer).setInt32(4, metadata.length, true);
bigEndianSchema.set(metadata, 8);
// The same RecordBatch message, with the 3 int32 values of its body in big-endian byte order. The metadata (the
// flatbuffer) stays little endian, as the format says.
const bigEndianBatch = stream.slice(batchStart, batchEnd);
const batchView = new DataView(bigEndianBatch.buffer);
for (let i = 0; i < values.length; i++) batchView.setInt32(batchBodyStart - batchStart + 4 * i, values[i]!, false);
const bigEndianStream = new Uint8Array([...bigEndianSchema, ...bigEndianBatch, ...stream.subarray(batchEnd)]);
const decoded = Message.getRootAsMessage(new flatbuffers.ByteBuffer(bigEndianStream.slice(8, 8 + metadata.length)));
console.log(`Schema.endianness of the changed stream: ${(decoded.header(new Schema()) as Schema).endianness()} (0 = Little, 1 = Big)`);
const read = (bytes: Uint8Array): string => {
try {
const table = A.tableFromIPC(bytes);
return `${table.numRows} rows, x = ${JSON.stringify(Array.from(table.getChild("x") ?? []))}`;
} catch (error) {
return `throws: ${(error as Error).message}`;
}
};
console.log(`little-endian stream: ${read(stream)}`);
const result = read(bigEndianStream);
console.log(`big-endian stream: ${result}`);
if (!result.startsWith("throws") && !result.includes("x = [1,2,3]")) {
console.log("BUG PRESENT: a stream with Schema.endianness = Big reads as little endian, with no byte swap and no error.");
process.exit(1);
}
console.log("OK: the reader byte-swaps the big-endian stream, or refuses it.");
Output:
Schema.endianness of the changed stream: 1 (0 = Little, 1 = Big)
little-endian stream: 3 rows, x = [1,2,3]
big-endian stream: 3 rows, x = [16777216,33554432,50331648]
BUG PRESENT: a stream with Schema.endianness = Big reads as little endian, with no byte swap and no error.
exit code: 1
Expected: [1, 2, 3] (the reader byte-swaps the buffers), or an error that says that the reader does not support a big-endian stream on this platform.
Cause: decodeSchema() in src/ipc/metadata/message.ts (lines 351 to 354) reads the fields and the custom metadata of the schema, but not _schema.endianness(). The Schema class has no field for it, and the record batch loader always reads the buffers in platform byte order.
Possible fix: Read _schema.endianness() in decodeSchema(). When it is not the platform byte order, throw an error that names the endianness. A later change can byte-swap the fixed-width buffers in the loader instead, as Arrow C++ does.
An AI coding assistant (Claude Code) found this fault, wrote the repro and wrote this text.
Component(s)
JavaScript
- Langage dominant
- TypeScript
- Étoiles
- 114
- Forks
- 35
- Merge moyen
- 13 h 35 min
- PR mergées (30 j)
- 5
Préparer son environnement
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de apache/arrow-js
-
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
Les mainteneurs répondent en général sous 1 jour
-
The IPC reader accepts a column that is shorter than its RecordBatch, and fills the missing rows with nullsPeut-être pris @Sealdot l’a pris il y a 1 jour. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
tableFromIPC loops with no end on a file whose RecordBatch block points at a DictionaryBatchPeut-être pris @aniket-r2Dev2 l’a pris il y a 3 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 80/100
apache/arrow-js#547 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
The stream reader drops a message of an unexpected type but not its body, and parses the body as the next messagesPeut-être pris @Umer-Butt07 l’a pris il y a 3 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 80/100
Les mainteneurs répondent en général sous 1 jour
-
The file reader accepts two non-delta DictionaryBatches for one id, and the column values change with no errorPeut-être pris @Sealdot l’a pris il y a 1 jour. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de apache/arrow-js
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
simstudioai/sim#10710 ·
Les mainteneurs répondent en général sous 1 jour
-
bug:new
Difficulté 2/5 1-3 heures Accessibilité débutants 73/100
callstackincubator/simlock#2088 ·
Les mainteneurs répondent en général sous 1 jour
-
Make the HTTP server's keep-alive and headers timeouts configurablePeut-être pris @mattgodbolt l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
compiler-explorer/compiler-explorer#9902 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 1-3 heures Accessibilité débutants 74/100
juspay/odu#193 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour