-
Notifications
You must be signed in to change notification settings - Fork 0
fix: guard quantiseAndSend against zero-length sequence and hidden dim #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -281,6 +281,14 @@ async function quantiseAndSend( | |
| hiddenDim: number, | ||
| dtype: EmbeddingMsg['dtype'], | ||
| ): Promise<void> { | ||
| if (seqLen < 1) { | ||
| workerLog('warn', 'quantiseAndSend: seqLen < 1; skipping Q² quantisation', { seqLen }); | ||
| return; | ||
| } | ||
| if (hiddenDim < 1) { | ||
| workerLog('warn', 'quantiseAndSend: hiddenDim < 1; skipping Q² quantisation', { hiddenDim }); | ||
| return; | ||
| } | ||
|
Comment on lines
+284
to
+291
|
||
| const n = hiddenDim; | ||
| const dtypeId = DTYPE_TO_Q2[dtype] ?? Q2_DTYPE_FP32; | ||
| try { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new guards prevent the seqLen=0/hiddenDim=0 trap, but quantiseAndSend still doesn’t validate other documented kernel preconditions (e.g., n must be a power of 2 and ≤ 16,384, and the buffer must contain at least the last-token row). Without these checks it’s still possible to call into the WASM kernel with unsupported dimensions or an undersized buffer, which can lead to traps or incorrect fingerprints. Consider extending the early validation to enforce the kernel’s n constraints (and, if applicable, the expected byteLength for the given dtype) before copying/calling into WASM.