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
This commit is contained in:
Jeff Raymakers
2025-06-30 13:19:31 -07:00
committed by GitHub
parent 8ec47ccec9
commit fc78019f25

View File

@@ -102,6 +102,11 @@ export class DuckDBDataReader extends DuckDBData {
// The row we're looking for is in this run. // The row we're looking for is in this run.
// Calculate the batch index and the row index in that batch. // Calculate the batch index and the row index in that batch.
batchIndex += Math.floor(currentRowIndex / run.batchSize); 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 rowIndexInBatch = currentRowIndex % run.batchSize;
const batch = this.batches[batchIndex]; const batch = this.batches[batchIndex];
return batch.value(columnIndex, rowIndexInBatch); return batch.value(columnIndex, rowIndexInBatch);