From fc78019f25783d38994a31781c460e45aed480e7 Mon Sep 17 00:00:00 2001 From: Jeff Raymakers Date: Mon, 30 Jun 2025 13:19:31 -0700 Subject: [PATCH] add bounds check to batch index in data reader (#16) * add bounds check to batch index in data reader * formatting * add columnIndex and rowIndex to error message --- ts/pkgs/duckdb-data-reader/src/DuckDBDataReader.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ts/pkgs/duckdb-data-reader/src/DuckDBDataReader.ts b/ts/pkgs/duckdb-data-reader/src/DuckDBDataReader.ts index 38fdd2a..220733a 100644 --- a/ts/pkgs/duckdb-data-reader/src/DuckDBDataReader.ts +++ b/ts/pkgs/duckdb-data-reader/src/DuckDBDataReader.ts @@ -102,6 +102,11 @@ export class DuckDBDataReader extends DuckDBData { // The row we're looking for is in this run. // Calculate the batch index and the row index in that batch. batchIndex += Math.floor(currentRowIndex / run.batchSize); + if (batchIndex < 0 || batchIndex >= this.batches.length) { + throw new Error( + `DuckDBDataReader with ${this.batches.length} batches calculated out-of-range batch index: ${batchIndex} (columnIndex=${columnIndex}, rowIndex=${rowIndex})`, + ); + } const rowIndexInBatch = currentRowIndex % run.batchSize; const batch = this.batches[batchIndex]; return batch.value(columnIndex, rowIndexInBatch);