tableFromIPC loops with no end on a file whose RecordBatch block points at a DictionaryBatch
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 80/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
- Lĩnh vực
- data
Hướng nghiên cứu
Bắt đầu trong src/ipc/reader.ts: RecordBatchFileReaderImpl._readNextMessageAndValidate() (dòng 668–677) và bản song sinh async của nó (743–752) gọi readMessage() mà không có kiểu, trong khi next() (504–530) chỉ tăng _recordBatchIndex trên nhánh RecordBatch. Chạy repro.ts của issue để xác nhận việc treo, sau đó khiến cả hai reader yêu cầu MessageHeader.RecordBatch, như readRecordBatch() làm ở dòng 639. Hoàn tất nghĩa là tệp được dựng thủ công ném invalidMessageType và tệp gốc trả về 3 dòng, cộng với một test hồi quy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug, including details regarding any error messages, version, and platform.
When a recordBatches block in the footer of an IPC file points at a DictionaryBatch message, tableFromIPC loops with no end. It does not return and does not throw. The repro writes a valid file with one dictionary column (610 bytes), then sets the offset of its RecordBatch block to the offset of its DictionaryBatch block. The read runs in a worker with a time limit of 5 seconds, and it gives no result.
The file is small and each length in it is small, so a limit on metadata and body lengths (as in PR #378) does not stop this loop. Issue #315 reports a file that makes tableFromIPC hang. I did not read that file, so I do not know if it has this cause, but it is possibly related.
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. In an IPC file, a RecordBatch block of the footer that points at a DictionaryBatch message
// makes RecordBatchFileReader loop with no end. The reader loads the dictionary, but it does not advance
// _recordBatchIndex. So it reads the same block again and again. The file has 610 bytes.
import { Worker } from "node:worker_threads";
import * as A from "apache-arrow";
import { Footer } from "apache-arrow/fb/footer";
import * as flatbuffers from "flatbuffers";
const type = new A.Dictionary(new A.Utf8(), new A.Int32(), 0);
const file = A.tableToIPC(new A.Table({ d: A.vectorFromArray(["a", "b", "a"], type) }), "file");
// The footer is before its 4-byte length and the magic "ARROW1". Each Block struct starts with offset (int64).
const view = new DataView(file.buffer, file.byteOffset, file.byteLength);
const footerLength = view.getInt32(file.length - 10, true);
const footerStart = file.length - 10 - footerLength;
const footer = Footer.getRootAsFooter(new flatbuffers.ByteBuffer(file.slice(footerStart, footerStart + footerLength)));
const dictionaryBlock = footer.dictionaries(0)!;
const batchBlock = footer.recordBatches(0)!;
// The same file, with the offset of the RecordBatch block set to the offset of the DictionaryBatch block.
const crafted = file.slice();
new DataView(crafted.buffer).setBigInt64(footerStart + batchBlock.bb_pos, dictionaryBlock.offset(), true);
console.log(`file of ${crafted.length} bytes: the RecordBatch block points at offset ${dictionaryBlock.offset()}, the DictionaryBatch.`);
// Each read runs in a worker with a time limit of 5 seconds.
const read = (bytes: Uint8Array): Promise<string> =>
new Promise((resolve) => {
const code = `
const { workerData, parentPort } = require("node:worker_threads");
import(workerData.url).then(({ tableFromIPC }) => {
try { parentPort.postMessage("returned " + tableFromIPC(workerData.bytes).numRows + " rows"); }
catch (error) { parentPort.postMessage("throws: " + error.message); }
});`;
const worker = new Worker(code, { eval: true, workerData: { url: import.meta.resolve("apache-arrow"), bytes } });
const timer = setTimeout(() => {
void worker.terminate();
resolve("no result after 5000 ms");
}, 5000);
worker.on("message", (message: string) => {
clearTimeout(timer);
void worker.terminate();
resolve(message);
});
});
console.log(`tableFromIPC(original file): ${await read(file)}`);
const result = await read(crafted);
console.log(`tableFromIPC(changed file): ${result}`);
if (result.startsWith("no result")) {
console.log("BUG PRESENT: tableFromIPC does not return and does not throw for the changed file.");
process.exit(1);
}
console.log("OK: tableFromIPC returns or throws for the changed file.");
Output:
file of 610 bytes: the RecordBatch block points at offset 8, the DictionaryBatch.
tableFromIPC(original file): returned 3 rows
tableFromIPC(changed file): no result after 5000 ms
BUG PRESENT: tableFromIPC does not return and does not throw for the changed file.
exit code: 1
Expected: An error, because the recordBatches blocks of the footer point at RecordBatch messages (File.fbs). Arrow C++ checks the message type of each block (CHECK_MESSAGE_TYPE in cpp/src/arrow/ipc/reader.cc).
Cause: RecordBatchFileReaderImpl._readNextMessageAndValidate() in src/ipc/reader.ts (lines 668 to 677) seeks to the block at _recordBatchIndex and calls this._reader.readMessage(type) with no type, so it accepts a message of each type. next() (lines 504 to 530) then takes the DictionaryBatch branch (lines 517 to 522). That branch loads the dictionary but does not advance _recordBatchIndex; only the RecordBatch branch does (line 512). So the loop reads the same block again, with no end. AsyncRecordBatchFileReaderImpl._readNextMessageAndValidate() (lines 743 to 752) has the same loop.
Possible fix: In both file readers, read the message of a recordBatches block with the type RecordBatch, for example this._reader.readMessage(type ?? MessageHeader.RecordBatch), as readRecordBatch() already does (line 639). Then a block that points at another message type throws invalidMessageType. The dictionary blocks are read in _readDictionaryBatch(), so they do not change.
An AI coding assistant (Claude Code) found this fault, wrote the repro and wrote this text.
Component(s)
JavaScript
- Ngôn ngữ chính
- TypeScript
- Star
- 114
- Fork
- 35
- Merge trung bình
- 13 giờ 35 phút
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Có Dockerfile hoặc tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/arrow-js
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
The IPC reader accepts a column that is shorter than its RecordBatch, and fills the missing rows with nullsCó thể đã có người làm @Sealdot đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
The IPC reader ignores Schema.endianness: a big-endian stream reads 1, 2, 3 as 16777216, 33554432, 50331648Có thể đã có người làm @aniket-r2Dev2 đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 1 ngày
-
The stream reader drops a message of an unexpected type but not its body, and parses the body as the next messagesCó thể đã có người làm @Umer-Butt07 đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 1 ngày
-
The file reader accepts two non-delta DictionaryBatches for one id, and the column values change with no errorCó thể đã có người làm @Sealdot đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của apache/arrow-js
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 74/100
juspay/odu#193 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Add: Alfa DramasĐang mởcheck:passed streams:add
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
ready-for-agent
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maduki-tech/bautackt#4 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
moq-dev/moq#10463 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày