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

Fix ConPTY inputs incorrectly being treated as plain text #16352

Merged
merged 3 commits into from
Dec 5, 2023

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Nov 21, 2023

This is my proposal to avoid aborting ConPTY input parsing because a read accidentally got split up into more than one chunk. This happens a lot with WSL for me, as I often get (for instance) a \x1b[67;46;99;0;32; input followed immediately by a 1_ input. The current logic would cause both of these to be flushed out to the client application.

This PR fixes the issue by only flushing either a standalone escape character or a escape+character combination. It basically limits the previous code to just VTStates::Ground and VTStates::Escape.

I'm not using the _state member, because VTStates::OscParam makes no distinction between \x1b] and \x1b]1234 and I only want to flush the former. I felt like checking the contents of run directly is easier to understand.

Related to #16343

Validation Steps Performed

  • win32-input-mode sequences are now properly buffered ✅
  • Standalone alt-key combinations are still being flushed ✅

@lhecker lhecker marked this pull request as ready for review December 1, 2023 19:15
@lhecker lhecker changed the title ConPTY: Fix a shutdown deadlock with WSL Fix ConPTY inputs incorrectly being treated as plain text Dec 2, 2023
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably sane, BUT I'd love for like, a test, or an addendum added to the comment above this block

@lhecker lhecker added Product-Conpty For console issues specifically related to conpty Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-0 Bugs that we consider release-blocking/recall-class (P0) zInbox-Bug Ignore me! labels Dec 4, 2023
Copy link
Member

@DHowett DHowett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly comfortable with this, but I wanted to get your opinion @j4james. We're gently skirting around the fact that we don't have a control sequence to input dispatcher that emits a buffered escape character after a timeout (e.g. the one in Vim that makes it possible to type ESC O and have it work "properly")...

I'm hesitant to add a timeout here since (1) we don't have the infrastructure for it and (2) that would compound with (e.g.) Vim's timeout.

This seems like the least-worst of all the worlds, where a Win32 input sequence spends 18 bytes in CsiParam state and if we catch any of them we want to continue buffering until we got the whole thing.

// Manually execute the last char [pwchCurr]
_processingLastCharacter = true;
switch (_state)
if (run.size() <= 2 && run.front() == L'\x1b')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lhecker make sure this works properly in Terminal, and with wsl vim

@j4james
Copy link
Collaborator

j4james commented Dec 5, 2023

I really like this. The only edge case I could think of that might be problematic is an Alt key combination where the second key is a surrogate pair. That would assumedly produce a 3 character sequence: ESC leading_char trailing char. But I'm not even sure whether that's something that can happen in practice, so I wouldn't be too worried about it.

@DHowett DHowett merged commit 5f5ef10 into main Dec 5, 2023
@DHowett DHowett deleted the dev/lhecker/win32-broken-input branch December 5, 2023 19:37
DHowett pushed a commit that referenced this pull request Dec 6, 2023
This is my proposal to avoid aborting ConPTY input parsing because a
read accidentally got split up into more than one chunk. This happens a
lot with WSL for me, as I often get (for instance) a
`\x1b[67;46;99;0;32;` input followed immediately by a `1_` input. The
current logic would cause both of these to be flushed out to the client
application.

This PR fixes the issue by only flushing either a standalone escape
character or a escape+character combination. It basically limits the
previous code to just `VTStates::Ground` and `VTStates::Escape`.

I'm not using the `_state` member, because `VTStates::OscParam` makes no
distinction between `\x1b]` and `\x1b]1234` and I only want to flush the
former. I felt like checking the contents of `run` directly is easier to
understand.

Related to #16343

## Validation Steps Performed
* win32-input-mode sequences are now properly buffered ✅
* Standalone alt-key combinations are still being flushed ✅

(cherry picked from commit 5f5ef10)
Service-Card-Id: 91270261
Service-Version: 1.19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-0 Bugs that we consider release-blocking/recall-class (P0) Product-Conpty For console issues specifically related to conpty zInbox-Bug Ignore me!
Projects
Development

Successfully merging this pull request may close these issues.

4 participants