Quickly invoking PowerShell menu completion multiple times crashes Terminal #21656

Open
opened 2026-01-31 07:51:07 +00:00 by claunia · 0 comments
Owner

Originally created by @krzysdz on GitHub (May 9, 2024).

Windows Terminal version

49e4eea60f

Windows build number

10.0.19045.4291

Other Software

No response

Steps to reproduce

  1. Enable experimental shell completion menu ("experimental.enableShellCompletionMenu": true)
  2. Quickly invoke shell completion multiple times, so that Terminal tries to parse JSON with completion data at the same time from multiple threads in one of the following ways:
    • Terminal versions from 432dfcc490 to 6d0342f0bb:
      1. Set up shell completion as described in How do I test this? section of Boost hashing performance with Robin Hood (#14938)
      2. Type something e.g. l
      3. Press Ctrl+Space multiple times
      4. Press any character key - because of #17204 this will send the completions generated in c. at the same time
    • Terminal versions 0b76c51ba1 and newer or older than 432dfcc490:
      1. Set up shell completion as described in How do I test this? section of #14938, but instead of
        $result += $completions.CompletionMatches | ConvertTo-Json -Compress
        
        append a large JSON string to $result. It doesn't have to be a valid shell completion data, but it should be a valid JSON. 7.6M characters is large enough to reproduce the bug on my computer and probably every other PC without trying to be fast.
      2. Type something e.g. l
      3. Press Ctrl+Space multiple times. Depending on your CPU and the JSON size it may or may not have to be done quickly.

Expected Behavior

Completion menu is shown or nothing happens

Actual Behavior

Terminal crashes or throws an exception or some kind of invalid memory access error, because JSON::CharReader in Command::ParsePowerShellMenuComplete is static and shared between threads:

49e4eea60f/src/cascadia/TerminalSettingsModel/Command.cpp (L693)

Reproduction in one of the versions affected by #17204:

https://github.com/microsoft/terminal/assets/12915102/693c214e-dbb2-47af-bb73-3b2a3f3efac9

Reproduction in other Terminal versions and demonstration of a possible fix (no menu is shown, because of the huge JSON, but the Terminal doesn't crash):

https://github.com/microsoft/terminal/assets/12915102/72dc5cb2-dd77-4f1f-a4dc-722f419a53e5

Originally created by @krzysdz on GitHub (May 9, 2024). ### Windows Terminal version 49e4eea60f737b46b8aeda505f4693df8a9d44a6 ### Windows build number 10.0.19045.4291 ### Other Software _No response_ ### Steps to reproduce 1. Enable experimental shell completion menu (`"experimental.enableShellCompletionMenu": true`) 2. Quickly invoke shell completion multiple times, so that Terminal tries to parse JSON with completion data at the same time from multiple threads in one of the following ways: - Terminal versions from 432dfcc4902d1a8393217a5f529d07e65182a3f8 to 6d0342f0bb31bf245843411c6781d6d5399ff651: 1. Set up shell completion as described in _How do I test this?_ section of #14938 2. Type something e.g. `l` 3. Press `Ctrl+Space` multiple times 4. Press any character key - because of #17204 this will send the completions generated in _c._ at the same time - Terminal versions 0b76c51ba10c81ba4213ba98cf88f2abdf91b15e and newer or older than 432dfcc4902d1a8393217a5f529d07e65182a3f8: 1. Set up shell completion as described in _How do I test this?_ section of #14938, but instead of ```ps $result += $completions.CompletionMatches | ConvertTo-Json -Compress ``` append a large JSON string to `$result`. It doesn't have to be a valid shell completion data, but it should be a valid JSON. 7.6M characters is large enough to reproduce the bug on my computer and probably every other PC without trying to be fast. 2. Type something e.g. `l` 3. Press `Ctrl+Space` multiple times. Depending on your CPU and the JSON size it may or may not have to be done quickly. ### Expected Behavior Completion menu is shown or nothing happens ### Actual Behavior Terminal crashes or throws an exception or some kind of invalid memory access error, because `JSON::CharReader` in `Command::ParsePowerShellMenuComplete` is `static` and shared between threads: https://github.com/microsoft/terminal/blob/49e4eea60f737b46b8aeda505f4693df8a9d44a6/src/cascadia/TerminalSettingsModel/Command.cpp#L693 Reproduction in one of the versions affected by #17204: https://github.com/microsoft/terminal/assets/12915102/693c214e-dbb2-47af-bb73-3b2a3f3efac9 Reproduction in other Terminal versions and demonstration of a possible fix (no menu is shown, because of the huge JSON, but the Terminal doesn't crash): https://github.com/microsoft/terminal/assets/12915102/72dc5cb2-dd77-4f1f-a4dc-722f419a53e5
claunia added the Issue-BugIn-PRNeeds-Tag-FixProduct-TerminalArea-TerminalControl labels 2026-01-31 07:51:08 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21656