Skip to content

Commit 899aeba

Browse files
committed
fix: guard remaining BigInt(float) crash sites in per-row WASM data registration
Previous fix (696c270) guarded filter parameter values but missed 3 per-row data conversion sites: operators.ts int64 filter/range buffer registration and wasm-engine.ts int-to-int64 promotion. BigInt(3.14) throws RangeError.
1 parent caf5205 commit 899aeba

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/operators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ function wasmFilterNumeric(
535535
const dst = new BigInt64Array(wasm.exports.memory.buffer, dataPtr, rowCount);
536536
for (let i = 0; i < rowCount; i++) {
537537
const v = values[i];
538-
dst[i] = typeof v === "bigint" ? v : BigInt((v as number) ?? 0);
538+
dst[i] = typeof v === "bigint" ? v : BigInt(Math.trunc((v as number) ?? 0));
539539
}
540540
const outPtr = wasm.exports.alloc(rowCount * 4);
541541
if (!outPtr) return null;
@@ -592,7 +592,7 @@ function wasmFilterRange(
592592
const dst = new BigInt64Array(wasm.exports.memory.buffer, dataPtr, rowCount);
593593
for (let i = 0; i < rowCount; i++) {
594594
const v = values[i];
595-
dst[i] = typeof v === "bigint" ? v : BigInt((v as number) ?? 0);
595+
dst[i] = typeof v === "bigint" ? v : BigInt(Math.trunc((v as number) ?? 0));
596596
}
597597
const outPtr = wasm.exports.alloc(rowCount * 4);
598598
if (!outPtr) return null;

src/wasm-engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ export class WasmEngine {
543543
const dataPtr = this.exports.alloc(rowCount * 8);
544544
if (!dataPtr) return false;
545545
const dst = new BigInt64Array(this.exports.memory.buffer, dataPtr, rowCount);
546-
for (let i = 0; i < rowCount; i++) dst[i] = BigInt(values[i] as number ?? 0);
546+
for (let i = 0; i < rowCount; i++) dst[i] = BigInt(Math.trunc((values[i] as number) ?? 0));
547547
this.exports.registerTableInt64(tPtr, tLen, cPtr, cLen, dataPtr, rowCount);
548548
return true;
549549
}

0 commit comments

Comments
 (0)