REP escape sequence with a large repeat count will hang conhost #7188

Open
opened 2026-01-31 00:57:20 +00:00 by claunia · 0 comments
Owner

Originally created by @j4james on GitHub (Mar 28, 2020).

Environment

Windows build number: Version 10.0.18362.657
Windows Terminal version (if applicable): Commit 28d108bf32

Steps to reproduce

  1. Build the OpenConsole solution from a recent commit
  2. Open a bash shell in conhost
  3. Run the command: printf "*\e[9999999999b"

Expected behavior

Technically we're asking the terminal to repeat the * character 10 billion times, but most terminals clamp their parameter values at a reasonable size. So I'd expect to see the * repeated several thousand times, but not billions.

For reference, the DEC specifications recommend a minimum of 16384, and both XTerm and VTE clamp parameters at 65535. Until recently I think we used to clamp them to 32767.

Actual behavior

The terminal hangs while eating up gigabytes of memory.

My recommendation would be to fix this in the state machine, because that potentially fixes or simplifies a bunch of other overflow problems too. See here:

7b9c8c7055/src/terminal/parser/stateMachine.cpp (L1429-L1434)

Worst case, though, we could fix this specific problem in the REP implementation here:

7b9c8c7055/src/terminal/parser/OutputStateMachineEngine.cpp (L527-L528)

Originally created by @j4james on GitHub (Mar 28, 2020). # Environment Windows build number: Version 10.0.18362.657 Windows Terminal version (if applicable): Commit 28d108bf32de4dce061d80a2bd160cd617c7e698 # Steps to reproduce 1. Build the OpenConsole solution from a recent commit 2. Open a bash shell in conhost 3. Run the command: `printf "*\e[9999999999b"` # Expected behavior Technically we're asking the terminal to repeat the `*` character 10 billion times, but most terminals clamp their parameter values at a reasonable size. So I'd expect to see the `*` repeated several thousand times, but not billions. For reference, the DEC specifications recommend a minimum of 16384, and both XTerm and VTE clamp parameters at 65535. Until recently I think we used to clamp them to 32767. # Actual behavior The terminal hangs while eating up gigabytes of memory. My recommendation would be to fix this in the state machine, because that potentially fixes or simplifies a bunch of other overflow problems too. See here: https://github.com/microsoft/terminal/blob/7b9c8c7055419b994f39092e46156d793c2c5b75/src/terminal/parser/stateMachine.cpp#L1429-L1434 Worst case, though, we could fix this specific problem in the `REP` implementation here: https://github.com/microsoft/terminal/blob/7b9c8c7055419b994f39092e46156d793c2c5b75/src/terminal/parser/OutputStateMachineEngine.cpp#L527-L528
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7188