Skip to content

tty(windows): make non-stdin ReadStream#setRawMode use VT raw mode - #34788

Closed
robobun wants to merge 6 commits into
mainfrom
farm/6ea66554/tty-setrawmode-vt-nonstdin
Closed

robobun wants to merge 6 commits into
mainfrom
farm/6ea66554/tty-setrawmode-vt-nonstdin

tty(windows): make non-stdin ReadStream#setRawMode use VT raw mode

ba6c918
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed Jul 20, 2026 in 29m 49s

Code review found 2 important issues

Found 4 candidates, confirmed 3. See review comments for details.

Details

Severity Count
🔴 Important 2
🟡 Nit 1
🟣 Pre-existing 0
Severity File:Line Issue
🔴 Important src/io/source.rs:584-595 Direct SetConsoleMode desyncs libuv's cached mode on the stdin uv_tty_t
🔴 Important src/jsc/bindings/ProcessBindingTTYWrap.cpp:199 asInt32() on unvalidated fd argument in Windows jsTTYSetMode
🟡 Nit src/io/source.rs:555-562 GetConsoleMode guard accepts console output handles

Annotations

Check failure on line 595 in src/io/source.rs

See this annotation in the file changed.

@claude claude / Claude Code Review

Direct SetConsoleMode desyncs libuv's cached mode on the stdin uv_tty_t

The `fd != 0` branch writes console mode via direct `SetConsoleMode`, but libuv caches the last-requested mode on the `stdin_tty` singleton (`tty.rd.mode.mode`) and `uv_tty_set_mode` short-circuits when requested==cached. So `process.stdin.setRawMode(true)` → CONIN$ stream `.setRawMode(false)` → `process.stdin.setRawMode(true)` no-ops, leaving the console cooked while `isRaw==true`. Since console input mode is per-buffer, routing every console-input fd through `uv_tty_set_mode` on the `stdin_tty

Check failure on line 199 in src/jsc/bindings/ProcessBindingTTYWrap.cpp

See this annotation in the file changed.

@claude claude / Claude Code Review

asInt32() on unvalidated fd argument in Windows jsTTYSetMode

`callFrame->argument(0)` is `this.fd`, a public user-mutable property that fs.ReadStream sets to `null` on close/destroy — `.asInt32()` on it debug-ASSERTs `isInt32()` and returns raw tag bits in release. Match the POSIX branch just below: check `fd.isNumber()` and use `fd.toInt32(globalObject)` under a throw scope (REVIEW.md: "coercing conversions (`toInt32(global)`, never `asInt32` on user values)").

Check warning on line 562 in src/io/source.rs

See this annotation in the file changed.

@claude claude / Claude Code Review

GetConsoleMode guard accepts console output handles

`GetConsoleMode` succeeds on console *output* handles too (it returns output-mode flags for screen-buffer handles), so this guard doesn't enforce the "non-console-input" invariant the comment claims. `new tty.ReadStream(1).setRawMode(true)` passes here, opens a fresh CONIN$, and silently raw-modes the process's console *input* buffer — pre-PR this errored, and Node/libuv returns EINVAL. Consider additionally requiring `GetNumberOfConsoleInputEvents(src, ...)` to succeed (only works on input hand