The stream reader drops a message of an unexpected type but not its body, and parses the body as the next messages
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 80/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, typescript
- 領域
- data
調査の方向性
両方のループは src/ipc/reader.ts にあり、RecordBatchStreamReaderImpl.next() は 504〜530 行目付近、AsyncRecordBatchStreamReaderImpl.next() は 579〜605 行目付近で、そこでは RecordBatch と DictionaryBatch の分岐だけが reader.readMessageBody(message.bodyLength) を呼んでいる。パッケージをビルドし、issue の repro.ts をそれに対して実行し、現状では 666 行で 1 で終了することを確認する。完了とは、repro が 0 で終了すること — 未知の header 型で両方のループが throw するか、両方が読み進める前に body を消費するかのいずれか — であり、既存の IPC reader テストが引き続き通ることである。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug, including details regarding any error messages, version, and platform.
The stream reader drops a message whose header type is not Schema, RecordBatch or DictionaryBatch (for example Tensor, SparseTensor or NONE), but it does not skip the body of that message. So the next read starts inside the body, and the reader parses the body as the next messages. A reader that frames each message by its bodyLength, as the encapsulated message format says, sees different messages in the same bytes.
The repro puts a Tensor message between the Schema and the RecordBatch of a valid stream of [1, 2, 3]. The body of the Tensor message is the complete RecordBatch message of a second stream of [666, 777, 888]. tableFromIPC returns 6 rows, [666, 777, 888, 1, 2, 3], with no error.
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 stream reader drops a message of an unexpected header type (for example Tensor), but it
// does not skip the body of that message. RecordBatchStreamReaderImpl.next() handles only Schema, RecordBatch and
// DictionaryBatch. So the reader parses the body as the next messages. A reader that frames each message by its
// bodyLength sees different rows in the same bytes.
import * as A from "apache-arrow";
import { Message } from "apache-arrow/fb/message";
import * as flatbuffers from "flatbuffers";
// This function gives the bounds of each message of a stream, and the root table of its metadata.
function messages(bytes: Uint8Array) {
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const found = [];
let start = 0;
while (start + 8 <= bytes.length) {
const metadataLength = view.getInt32(start + 4, true);
if (metadataLength === 0) {
found.push({ start, metadataEnd: start + 8, end: start + 8, header: "EOS", bodyLength: 0, fb: null });
break;
}
const metadataEnd = start + 8 + metadataLength;
const fb = Message.getRootAsMessage(new flatbuffers.ByteBuffer(bytes.slice(start + 8, metadataEnd)));
const bodyLength = Number(fb.bodyLength());
found.push({ start, metadataEnd, end: metadataEnd + bodyLength, header: A.MessageHeader[fb.headerType()], bodyLength, fb });
start = metadataEnd + bodyLength;
}
return found;
}
const visible = A.tableToIPC(A.tableFromArrays({ x: Int32Array.of(1, 2, 3) }), "stream");
const hidden = A.tableToIPC(A.tableFromArrays({ x: Int32Array.of(666, 777, 888) }), "stream");
const [schema, batch, end] = messages(visible);
const hiddenBatch = messages(hidden)[1]!;
const hiddenBytes = hidden.slice(hiddenBatch.start, hiddenBatch.end);
// A Tensor message: the prefix and metadata of the RecordBatch, with the header type 4 (Tensor) and a bodyLength
// that covers the complete RecordBatch message of the hidden stream. Message field 1 (vtable offset 6) is
// header_type and field 3 (vtable offset 10) is bodyLength.
const fb = batch!.fb!;
const tensor = visible.slice(batch!.start, batch!.metadataEnd);
const headerTypePosition = 8 + fb.bb_pos + fb.bb!.__offset(fb.bb_pos, 6);
const bodyLengthPosition = 8 + fb.bb_pos + fb.bb!.__offset(fb.bb_pos, 10);
tensor[headerTypePosition] = A.MessageHeader.Tensor;
new DataView(tensor.buffer).setBigInt64(bodyLengthPosition, BigInt(hiddenBytes.length), true);
const crafted = new Uint8Array([
...visible.subarray(schema!.start, schema!.end),
...tensor,
...hiddenBytes,
...visible.subarray(batch!.start, batch!.end),
...visible.subarray(end!.start, end!.end),
]);
console.log(`messages by bodyLength: ${messages(crafted).map((m) => `${m.header} (body ${m.bodyLength})`).join(", ")}`);
const rows = (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(`tableFromIPC(original stream): ${rows(visible)}`);
const result = rows(crafted);
console.log(`tableFromIPC(stream with the Tensor message): ${result}`);
if (result.includes("666")) {
console.log("BUG PRESENT: the reader returns the rows 666, 777 and 888 from the body of the Tensor message.");
process.exit(1);
}
console.log("OK: the reader skips the body of the Tensor message, or refuses the message.");
Output:
messages by bodyLength: Schema (body 0), Tensor (body 160), RecordBatch (body 16), EOS (body 0)
tableFromIPC(original stream): 3 rows, x = [1,2,3]
tableFromIPC(stream with the Tensor message): 6 rows, x = [666,777,888,1,2,3]
BUG PRESENT: the reader returns the rows 666, 777 and 888 from the body of the Tensor message.
exit code: 1
Expected: An error for a message type that the stream format does not permit, or a reader that skips bodyLength bytes of the message before it reads the next one. The rows 666, 777 and 888 are not in the stream when each message is framed by its bodyLength.
Cause: RecordBatchStreamReaderImpl.next() in src/ipc/reader.ts (lines 504 to 530) has a branch for isSchema(), isRecordBatch() and isDictionaryBatch(), and no else. Only the RecordBatch and DictionaryBatch branches call reader.readMessageBody(message.bodyLength). For each other header type the loop reads the next message from the current position, which is the start of the body. AsyncRecordBatchStreamReaderImpl.next() (lines 579 to 605) has the same loop.
Possible fix: Add an else branch to both loops that throws an error that names the header type, because a stream holds only Schema, DictionaryBatch and RecordBatch messages. If the reader must accept such messages, the else branch can read and drop the body with reader.readMessageBody(message.bodyLength).
An AI coding assistant (Claude Code) found this fault, wrote the repro and wrote this text.
Component(s)
JavaScript
- 主要言語
- TypeScript
- スター
- 114
- フォーク
- 35
- 平均マージ
- 13時間 35分
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/arrow-js のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信
-
The IPC reader accepts a column that is shorter than its RecordBatch, and fills the missing rows with nulls対応中かも @Sealdot が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
The IPC reader ignores Schema.endianness: a big-endian stream reads 1, 2, 3 as 16777216, 33554432, 50331648対応中かも @aniket-r2Dev2 が 2 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
tableFromIPC loops with no end on a file whose RecordBatch block points at a DictionaryBatch対応中かも @aniket-r2Dev2 が 3 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 80/100
apache/arrow-js#547 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
The file reader accepts two non-delta DictionaryBatches for one id, and the column values change with no error対応中かも @Sealdot が 1 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
apache/arrow-js の issue をすべて見る
似ている issue
-
難易度 1/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
Add: Alfa Dramasオープンcheck:passed streams:add
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
ready-for-agent
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Maduki-tech/bautackt#4 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
moq-dev/moq#10463 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信