text-decoder: snapshot shared buffers before decoding - #31643
text-decoder: snapshot shared buffers before decoding#31643EffortlessSteven wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
💤 Files with no reviewable changes (1)
Walkthrough
ChangesTextDecoder SharedArrayBuffer Safety
Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
65f8404 to
7f4bcd3
Compare
|
Thanks for this. The same fix landed on main in #33072 (merged July 4): I ran the nine "SharedArrayBuffer input" tests from this branch against current main (04148c8, debug build) and they all pass, including the concurrent worker mutation case across several runs. Closing since main already has this behavior. If you run into a remaining case on a current canary, please open an issue and we will take a look. |
Summary
TextDecoder.decode()accepted SharedArrayBuffer-backed inputs and decoded them through a&[u8]built from JS backing storage. Another JS agent can mutate that shared memory while Rust holds the slice, which is undefined behavior under Rust's aliasing rules.This keeps fixed unshared inputs on the borrowed fast path, and snapshots shared or resizable inputs into a fresh non-shared buffer before decoding.
Changes:
TextDecoder.decodeDOMJIT fast path so SAB-backed typed arrays use the safe pathTest approach
The regression uses a worker mutating SharedArrayBuffer-backed input while
TextDecoder.decode()runs. The unpatched debug build crashes in the UTF-8 materializer; the patched build exits cleanly.Verification
Review map
src/runtime/webcore/TextDecoder.rs: snapshot shared/resizable BufferSource input before creating the decode slicesrc/runtime/webcore/encoding.classes.ts: remove the DOMJIT fast path so SAB-backed typed arrays cannot bypass the snapshot pathtest/js/web/encoding/text-decoder.test.js: cover SAB-backed UTF-8 / UTF-16, offset, zero-length, growable/resizable inputs, and concurrent mutation