fix(terminal): hand xterm an owned Uint8Array copy, not a wasm-memory view #55

Merged
Claude-Run merged 1 commit from fix/VAPP-46-xterm-write-owned-copy into main 2026-06-29 02:39:18 +02:00
Member

Bind xterm's write to take a js_sys::Uint8Array instead of &[u8]. A &[u8] marshals as a transient view over wasm linear memory valid only for the synchronous duration of the call, but xterm's write is async: it buffers the argument and parses it on a later microtask/timer. By then the wasm Vec can be overwritten by the next frame or wasm memory growth can detach the view's ArrayBuffer, corrupting or dropping bytes mid-stream (eaten leading characters, leaked ANSI escape fragments).

Pass js_sys::Uint8Array::from(&bytes[..]), which copies into a fresh JS-heap buffer that never aliases wasm memory and survives the deferred parse. Route the on_close notice write through the same owned-copy path for consistency. convertEol is left unchanged (PTY master read already includes ONLCR \r\n).

#VAPP-46

Bind xterm's `write` to take a `js_sys::Uint8Array` instead of `&[u8]`. A `&[u8]` marshals as a transient view over wasm linear memory valid only for the synchronous duration of the call, but xterm's `write` is async: it buffers the argument and parses it on a later microtask/timer. By then the wasm Vec can be overwritten by the next frame or wasm memory growth can detach the view's ArrayBuffer, corrupting or dropping bytes mid-stream (eaten leading characters, leaked ANSI escape fragments). Pass `js_sys::Uint8Array::from(&bytes[..])`, which copies into a fresh JS-heap buffer that never aliases wasm memory and survives the deferred parse. Route the `on_close` notice write through the same owned-copy path for consistency. `convertEol` is left unchanged (PTY master read already includes ONLCR `\r\n`). #VAPP-46
fix(terminal): hand xterm an owned Uint8Array copy, not a wasm-memory view
All checks were successful
Check / fmt + clippy + build + tests (pull_request) Successful in 1m10s
Create release / Create release from merged PR (pull_request) Has been skipped
8101f54a87
Bind xterm's `write` to take a `js_sys::Uint8Array` instead of `&[u8]`. A `&[u8]` marshals as a transient view over wasm linear memory valid only for the synchronous duration of the call, but xterm's `write` is async: it buffers the argument and parses it on a later microtask/timer. By then the wasm Vec can be overwritten by the next frame or wasm memory growth can detach the view's ArrayBuffer, corrupting or dropping bytes mid-stream (eaten leading characters, leaked ANSI escape fragments).

Pass `js_sys::Uint8Array::from(&bytes[..])`, which copies into a fresh JS-heap buffer that never aliases wasm memory and survives the deferred parse. Route the `on_close` notice write through the same owned-copy path for consistency. `convertEol` is left unchanged (PTY master read already includes ONLCR `\r\n`).

#VAPP-46
David deleted branch fix/VAPP-46-xterm-write-owned-copy 2026-06-29 02:42:38 +02:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
psa-systems/vervain-apps!55
No description provided.