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

Closed
opened 2026-01-31 07:42:59 +00:00 by claunia · 10 comments
Owner

Originally created by @segrey on GitHub (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.

Originally created by @segrey on GitHub (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](https://github.com/microsoft/terminal/releases/tag/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: ```text 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](https://github.com/microsoft/terminal/assets/607109/04736caa-de74-4e02-9d8e-4151f4c0124f) Looks like it's caused by crashing [`swprintf_s`](https://github.com/microsoft/terminal/blob/a38388615e299658072f906578acd60e976fe787/src/winconpty/winconpty.cpp#L142), 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.
claunia added the Issue-BugIn-PRNeeds-Tag-FixArea-ServerProduct-Conpty labels 2026-01-31 07:43:00 +00:00
Author
Owner

@DHowett commented on GitHub (Mar 11, 2024):

Wow, great catch!

@DHowett commented on GitHub (Mar 11, 2024): Wow, great catch!
Author
Owner

@a-usr commented on GitHub (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?

@a-usr commented on GitHub (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?
Author
Owner

@hurricup commented on GitHub (Mar 19, 2024):

@a-usr you may check the linked issue https://github.com/JetBrains/pty4j/issues/145 for the history

@hurricup commented on GitHub (Mar 19, 2024): @a-usr you may check the linked issue https://github.com/JetBrains/pty4j/issues/145 for the history
Author
Owner

@a-usr commented on GitHub (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!

@a-usr commented on GitHub (Mar 19, 2024): > @a-usr you may check the linked issue [JetBrains/pty4j#145](https://github.com/JetBrains/pty4j/issues/145) for the history To be honest I thought there was more to it. But thanks for the link!
Author
Owner

@hurricup commented on GitHub (Mar 19, 2024):

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

@hurricup commented on GitHub (Mar 19, 2024): Nope, just tests involving running from gradle long paths failed all the sudden
Author
Owner

@segrey commented on GitHub (Mar 19, 2024):

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

@segrey commented on GitHub (Mar 19, 2024): @a-usr Initially, it was discovered by IntelliJ plugin developers. Also, please see [IDEA-347968](https://youtrack.jetbrains.com/issue/IDEA-347968/Terminal-IDE-fatal-crash-Execution-failed-for-task-runIde-or-if-installation-path-155-characters#focus=Comments-27-9510169.0-0) for more details.
Author
Owner

@a-usr commented on GitHub (Mar 20, 2024):

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

@a-usr commented on GitHub (Mar 20, 2024): Anyhow, awesome that you found/helped to find this bug!
Author
Owner

@segrey commented on GitHub (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.

@segrey commented on GitHub (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](https://github.com/microsoft/terminal/releases/tag/v1.21.2361.0) as of now) doesn't contain it.
Author
Owner

@lhecker commented on GitHub (Sep 9, 2024):

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

@lhecker commented on GitHub (Sep 9, 2024): I'll mark it up for a backport to 1.21. That will take probably about 2 weeks.
Author
Owner

@DHowett commented on GitHub (Sep 17, 2024):

I just pulled this into 1.21 after conflict resolution.

@DHowett commented on GitHub (Sep 17, 2024): I just pulled this into 1.21 after conflict resolution.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21379