From fb545e80d67dd8abe4ee90361c3db3063495fd5a Mon Sep 17 00:00:00 2001 From: Faur Ioan-Aurel Date: Fri, 24 Oct 2025 22:34:29 +0300 Subject: [PATCH 1/2] fix: pseudo console initialization for SSH sessions Resolved an invalid parameter error (-2147024809) during PTY creation on Windows 11 22H2 (but not only) when connecting via JetBrains Toolbox. CreatePseudoConsole doesn't accept a 0x0 (zero width and zero height) console size. Toolbox uses the default native client which apparently sends the width and height set to 0 in ssh req opts. Unfortunately, there is NO explicit documentation in the official Microsoft documentation that states the minimum valid values or explicitly prohibits 0x0. Looking at real-world implementations in the search results, all examples use reasonable non-zero values. I tested this with a local Windows VM registered to dev.coder.com i.e. externally managed workspace. Fixes: #20468 --- pty/pty_windows.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pty/pty_windows.go b/pty/pty_windows.go index 93fea12019627..68bc182899815 100644 --- a/pty/pty_windows.go +++ b/pty/pty_windows.go @@ -54,10 +54,21 @@ func newPty(opt ...Option) (*ptyWindows, error) { return nil, err } - consoleSize := uintptr(80) + (uintptr(80) << 16) + // Default dimensions + width := uint16(80) + height := uint16(80) + if opts.sshReq != nil { - consoleSize = uintptr(opts.sshReq.Window.Width) + (uintptr(opts.sshReq.Window.Height) << 16) + if opts.sshReq.Window.Width > 0 { + width = opts.sshReq.Window.Width + } + if opts.sshReq.Window.Height > 0 { + height = opts.sshReq.Window.Height + } } + + consoleSize := uintptr(width) + (uintptr(height) << 16) + ret, _, err := procCreatePseudoConsole.Call( consoleSize, uintptr(pty.inputRead.Fd()), From d529139590914480fee3a7c3e574b0a10901e752 Mon Sep 17 00:00:00 2001 From: Faur Ioan-Aurel Date: Fri, 24 Oct 2025 23:16:02 +0300 Subject: [PATCH 2/2] Added upper bound validation (<= 65535) to ensure the values fit in uint16 --- pty/pty_windows.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/pty/pty_windows.go b/pty/pty_windows.go index 68bc182899815..987ef02eb281d 100644 --- a/pty/pty_windows.go +++ b/pty/pty_windows.go @@ -55,20 +55,18 @@ func newPty(opt ...Option) (*ptyWindows, error) { } // Default dimensions - width := uint16(80) - height := uint16(80) - + width, height := 80, 80 if opts.sshReq != nil { - if opts.sshReq.Window.Width > 0 { - width = opts.sshReq.Window.Width + if w := opts.sshReq.Window.Width; w > 0 && w <= 65535 { + width = w } - if opts.sshReq.Window.Height > 0 { - height = opts.sshReq.Window.Height + if h := opts.sshReq.Window.Height; h > 0 && h <= 65535 { + height = h } } - + consoleSize := uintptr(width) + (uintptr(height) << 16) - + ret, _, err := procCreatePseudoConsole.Call( consoleSize, uintptr(pty.inputRead.Fd()),