File: worker-pool.js line 154 Problem: After slice(), transfers original buffer instead of sliced buffer. Causes race condition and potential memory corruption. Fix: Ensure task.data.buffer refers to the sliced buffer, not original.
File: worker-pool.js line 102-122 Problem: After _waitForWorker() returns, another concurrent call could grab the worker. workerId ends up as -1, causing crash on workers[-1]. Fix: Use atomic claim - set workerReady[i] = false immediately when found.
File: bao-rust-worker.js line 16-28 Problem: Buffer size hardcoded to 65536 (64KB) but Rust uses 1MB. Views point to wrong memory range. Fix: Export get_input_size() and get_output_size() from Rust, use in JS.
File: rust-bao/src/lib.rs Problem: static mut buffers work but are fragile. Reentrancy or async interleaving could corrupt. Fix: Either use thread_local! RefCell pattern or document safety requirements.
File: worker-pool.js line 229-240 Problem: If worker doesn't respond to shutdown, timeout resolves but worker keeps running. Fix: Call worker.terminate() after timeout if not exited.
File: bao-rust-worker.js line 118-155 Problem: msg.taskId could be undefined, error handling incomplete. Fix: Default taskId, validate required fields, include stack trace.
File: bao.js loadBlockFast() Problem: No check for detached buffers or bounds. Fix: Add buffer.byteLength check and bounds validation.
File: rust-bao/src/lib.rs Problem: No bounds check - num_leaves > INPUT_SIZE/32 causes panic. Fix: Return Result with error for too many leaves.
File: worker-pool.js line 256 Problem: numWorkers ignored on subsequent calls. Fix: Warn if numWorkers differs from existing pool.
File: worker-pool.js line 108 Problem: Dead worker marked not ready but pending tasks not rejected. Fix: Reject pending tasks, optionally restart worker.
Extract common worker handler logic to shared module.
Add proper .d.ts files for ParallelBaoProcessor and PersistentWorkerPool.
- Fix #1 (buffer transfer) - 30 min
- Fix #2 (race condition) - 30 min
- Fix #3 (buffer sizes) - 30 min, requires Rust rebuild
- Fix #8 (bounds check) - 30 min
- Fix #5 (shutdown) - 15 min
- Fix #6 (error handling) - 15 min
- Run full test suite
- Bump to v1.3.2, commit, push, npm publish
Estimated time: 2-3 hours