Skip to content

Commit 696c270

Browse files
committed
fix: guard all BigInt(float) crash sites in WASM filter + column registration
6 unguarded BigInt() calls that would throw on non-integer values: - operators.ts: filterInt64Buffer, filterInt64Range, filterInt64NotRange (user filter values on int64 columns) - local-executor.ts, master-do.ts: BigInt64Array column registration (mixed-type rows where sample was integer but later values are floats) All now use Math.trunc before BigInt conversion, matching the pattern established in decode.ts and sql/evaluator.ts.
1 parent 92cabf7 commit 696c270

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/local-executor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class LocalExecutor implements QueryExecutor {
118118
if (typeof sample === "number") {
119119
if (Number.isInteger(sample)) {
120120
const arr = new BigInt64Array(rows.length);
121-
for (let i = 0; i < rows.length; i++) arr[i] = BigInt(rows[i][colName] as number);
121+
for (let i = 0; i < rows.length; i++) { const v = rows[i][colName]; arr[i] = typeof v === "bigint" ? v : BigInt(Math.trunc(Number(v ?? 0))); }
122122
columnArrays.push({ name: colName, dtype: "int64", values: arr.buffer });
123123
} else {
124124
const arr = new Float64Array(rows.length);

src/master-do.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export class MasterDO extends DurableObject<Env> {
157157
if (typeof sampleValue === "number") {
158158
if (Number.isInteger(sampleValue)) {
159159
const i64 = new BigInt64Array(rows.length);
160-
for (let i = 0; i < rows.length; i++) i64[i] = BigInt(rows[i][colName] as number);
160+
for (let i = 0; i < rows.length; i++) { const v = rows[i][colName]; i64[i] = typeof v === "bigint" ? v : BigInt(Math.trunc(Number(v ?? 0))); }
161161
columnArrays.push({ name: colName, dtype: "int64", values: i64.buffer });
162162
} else {
163163
const f64 = new Float64Array(rows.length);

src/operators.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ function wasmFilterNumeric(
540540
const outPtr = wasm.exports.alloc(rowCount * 4);
541541
if (!outPtr) return null;
542542
const count = wasm.exports.filterInt64Buffer(
543-
dataPtr, rowCount, op, BigInt(filterValue), outPtr, rowCount,
543+
dataPtr, rowCount, op, BigInt(Math.trunc(filterValue as number)), outPtr, rowCount,
544544
);
545545
return new Uint32Array(wasm.exports.memory.buffer.slice(outPtr, outPtr + count * 4));
546546
}
@@ -597,7 +597,7 @@ function wasmFilterRange(
597597
const outPtr = wasm.exports.alloc(rowCount * 4);
598598
if (!outPtr) return null;
599599
const fn = negate ? wasm.exports.filterInt64NotRange : wasm.exports.filterInt64Range;
600-
const count = fn(dataPtr, rowCount, BigInt(low), BigInt(high), outPtr, rowCount);
600+
const count = fn(dataPtr, rowCount, BigInt(Math.trunc(low as number)), BigInt(Math.trunc(high as number)), outPtr, rowCount);
601601
return new Uint32Array(wasm.exports.memory.buffer.slice(outPtr, outPtr + count * 4));
602602
}
603603

@@ -2032,8 +2032,8 @@ export class WasmAggregateOperator implements Operator {
20322032
: this.wasm.exports.filterFloat64Range(dataPtr, rowCount, f.value[0] as number, f.value[1] as number, outPtr, rowCount);
20332033
} else if (col.dtype === "int64") {
20342034
count = isNotBetween
2035-
? this.wasm.exports.filterInt64NotRange(dataPtr, rowCount, BigInt(f.value[0] as number), BigInt(f.value[1] as number), outPtr, rowCount)
2036-
: this.wasm.exports.filterInt64Range(dataPtr, rowCount, BigInt(f.value[0] as number), BigInt(f.value[1] as number), outPtr, rowCount);
2035+
? this.wasm.exports.filterInt64NotRange(dataPtr, rowCount, BigInt(Math.trunc(f.value[0] as number)), BigInt(Math.trunc(f.value[1] as number)), outPtr, rowCount)
2036+
: this.wasm.exports.filterInt64Range(dataPtr, rowCount, BigInt(Math.trunc(f.value[0] as number)), BigInt(Math.trunc(f.value[1] as number)), outPtr, rowCount);
20372037
} else {
20382038
count = isNotBetween
20392039
? this.wasm.exports.filterInt32NotRange(dataPtr, rowCount, f.value[0] as number, f.value[1] as number, outPtr, rowCount)
@@ -2045,7 +2045,7 @@ export class WasmAggregateOperator implements Operator {
20452045
if (col.dtype === "float64") {
20462046
count = this.wasm.exports.filterFloat64Buffer(dataPtr, rowCount, wasmOp, f.value as number, outPtr, rowCount);
20472047
} else if (col.dtype === "int64") {
2048-
count = this.wasm.exports.filterInt64Buffer(dataPtr, rowCount, wasmOp, BigInt(f.value as number), outPtr, rowCount);
2048+
count = this.wasm.exports.filterInt64Buffer(dataPtr, rowCount, wasmOp, BigInt(Math.trunc(f.value as number)), outPtr, rowCount);
20492049
} else {
20502050
count = this.wasm.exports.filterInt32Buffer(dataPtr, rowCount, wasmOp, f.value as number, outPtr, rowCount);
20512051
}

0 commit comments

Comments
 (0)