Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CreatePseudoConsole crashes due to long path to conpty.dll #16860

Closed
segrey opened this issue Mar 11, 2024 · 10 comments · Fixed by #17768
Closed

CreatePseudoConsole crashes due to long path to conpty.dll #16860

segrey opened this issue Mar 11, 2024 · 10 comments · Fixed by #17768
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Conpty For console issues specifically related to conpty

Comments

@segrey
Copy link

segrey commented Mar 11, 2024

Windows Terminal version

1.19.10573.0

Windows build number

10.0.22631.0

Other Software

No response

Steps to reproduce

  1. Install Windows Terminal v1.19.10573.0 to a directory with long full path: the parent directory of WindowsTerminal.exe should have length 167 chars or higher.
  2. Run WindowsTerminal.exe

Please see https://github.com/segrey/CreatePseudoConsole-crash-with-long-path, it automates the reproduction of this issue.

Expected Behavior

Windows Terminal runs normally.

Actual Behavior

Windows Terminal crashes at startup and finishes with exit code -1073740791 (hex: c0000409)

Event Viewer (Windows Log | Application) contains the following error:

Faulting application name: WindowsTerminal.exe, version: 1.19.2402.26003, time stamp: 0x65dce3ea
Faulting module name: ucrtbase.dll, version: 10.0.22621.2506, time stamp: 0x097c794c
Exception code: 0xc0000409
Fault offset: 0x000000000007df28
Faulting process id: 0x0x4424
Faulting application start time: 0x0x1DA739C0BB31B88
Faulting application path: D:\CreatePseudoConsole-crash-with-long-path\tmp\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaa\terminal-1.19.10573.0\WindowsTerminal.exe
Faulting module path: C:\WINDOWS\System32\ucrtbase.dll
Report Id: 201c4d23-ff42-474b-8764-703686bc06cc
Faulting package full name: 
Faulting package-relative application ID: 

Running the WindowsTerminal.exe with WinDbg shows that the problem is in CreatePseudoConsole function:

image

Looks like it's caused by crashing swprintf_s, because MAX_PATH (260) is too small to accomodate the full path. This is indirectly confirmed by the following: WindowsTerminal.exe doesn't crash when it's located in a directory with full path length 162 chars -- in this case the command line of OpenConsole.exe is 259 chars and everything works correctly:

"D:\CreatePseudoConsole-crash-with-long-path\tmp\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aaaaaaaa\aa\terminal-1.19.10573.0\OpenConsole.exe" --headless --resizeQuirk --width 120 --height 30 --signal 0xd28 --server 0xd20

It'd be great to fix this issue, because sometimes conpty.dll / OpenConsole.exe are located deep inside the file system.

@segrey segrey added Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Mar 11, 2024
@DHowett
Copy link
Member

DHowett commented Mar 11, 2024

Wow, great catch!

@a-usr
Copy link

a-usr commented Mar 19, 2024

Im wondering, how did you even discover this in the first place? Are you one of those people that name their directories like Java Classes?

@hurricup
Copy link

@a-usr you may check the linked issue JetBrains/pty4j#145 for the history

@a-usr
Copy link

a-usr commented Mar 19, 2024

@a-usr you may check the linked issue JetBrains/pty4j#145 for the history

To be honest I thought there was more to it. But thanks for the link!

@hurricup
Copy link

Nope, just tests involving running from gradle long paths failed all the sudden

@segrey
Copy link
Author

segrey commented Mar 19, 2024

@a-usr Initially, it was discovered by IntelliJ plugin developers. Also, please see IDEA-347968 for more details.

@a-usr
Copy link

a-usr commented Mar 20, 2024

Anyhow, awesome that you found/helped to find this bug!

@zadjii-msft zadjii-msft added Product-Conpty For console issues specifically related to conpty Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Mar 20, 2024
@zadjii-msft zadjii-msft added this to the Terminal v1.21 milestone Mar 20, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the In-PR This issue has a related PR label Aug 22, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Tag-Fix Doesn't match tag requirements label Aug 22, 2024
@segrey
Copy link
Author

segrey commented Sep 5, 2024

@lhecker Thanks for fixing it. Do you know in when a stable Terminal v1.21 with the fix will be released? Seems the latest release (Windows Terminal v1.21.2361.0 as of now) doesn't contain it.

@lhecker
Copy link
Member

lhecker commented Sep 9, 2024

I'll mark it up for a backport to 1.21. That will take probably about 2 weeks.

DHowett pushed a commit that referenced this issue Sep 17, 2024
Swapped the `swprintf_s` with no failure checks against a
`str_printf_nothrow` with checks. I also deduplicated the
`CreateProcess` calls since they're mostly identical.

Closes #16860

(cherry picked from commit b3f4162)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgS25_o
Service-Version: 1.21
@DHowett
Copy link
Member

DHowett commented Sep 17, 2024

I just pulled this into 1.21 after conflict resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Server Down in the muck of API call servicing, interprocess communication, eventing, etc. In-PR This issue has a related PR Issue-Bug It either shouldn't be doing this or needs an investigation. Needs-Tag-Fix Doesn't match tag requirements Product-Conpty For console issues specifically related to conpty
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants