Repository navigation
Closed
Labels
Area-InputRelated to input processing (key presses, mouse, etc.)Related to input processing (key presses, mouse, etc.)In-PRThis issue has a related PRThis issue has a related PRIssue-BugIt either shouldn't be doing this or needs an investigation.It either shouldn't be doing this or needs an investigation.Needs-AttentionThe core contributors need to come back around and look at this ASAP.The core contributors need to come back around and look at this ASAP.Needs-Tag-FixDoesn't match tag requirementsDoesn't match tag requirementsPriority-1A description (P1)A description (P1)Product-ConhostFor issues in the Console codebaseFor issues in the Console codebaseSeverity-CrashCrashes are real bad news.Crashes are real bad news.
Milestone
Description
Environment
Windows build number: 10.0.19041.630]
Windows Terminal version (if applicable):
Any other software?
tcsh (native Windows version)
# Steps to reproduce
download tcsh-x64.exe from https://github.com/amoldeshpande/tcsh/releases/tag/20210103.10
Launch tcsh. Doesn't have to be in terminal. Paste any emoji into it. It will crash conhost.exe on Windows 10 2004 and OpenConsole.exe if you launch within Windows Terminal
# Expected behavior
Should paste an emoji
# Actual behavior
Edited: repro steps with tcsh. Cannnot repro it with my test program anymore
Metadata
Metadata
Assignees
Labels
Area-InputRelated to input processing (key presses, mouse, etc.)Related to input processing (key presses, mouse, etc.)In-PRThis issue has a related PRThis issue has a related PRIssue-BugIt either shouldn't be doing this or needs an investigation.It either shouldn't be doing this or needs an investigation.Needs-AttentionThe core contributors need to come back around and look at this ASAP.The core contributors need to come back around and look at this ASAP.Needs-Tag-FixDoesn't match tag requirementsDoesn't match tag requirementsPriority-1A description (P1)A description (P1)Product-ConhostFor issues in the Console codebaseFor issues in the Console codebaseSeverity-CrashCrashes are real bad news.Crashes are real bad news.
Activity
j4james commentedon Dec 27, 2020
Irrespective of whether emojis are expected to work in these conditions, it seems very wrong to me that an error condition here would cause the entire process to terminate. I'm convinced that half of the
FAIL_FASTcalls in the code are unintentional, and the original author was likely expecting an error to be returned, or an exception to be thrown (much like all the places we're mistakenly usinggsl::narrowinstead ofgsl::narrow_cast).KalleOlaviNiemitalo commentedon Dec 27, 2020
I cannot reproduce the crash when right-click pasting 😀 (U+1F600) or 👨👩👧👦 (U+1F468 U+200D U+1F469 U+200D U+1F467 U+200D U+1F466) to OpenConsole.exe copied from Windows Terminal 1.4.3243.0, with the demo program built for x86, on Windows 10 version 20H2 (19042.685), where the setting "Beta: Use Unicode UTF-8 for worldwide language support" is off.
I don't see why SetFileApisToANSI would even matter here; doesn't it only affect the encoding of file names, which the demo program does not use?
j4james commentedon Dec 27, 2020
Kalle Olavi Niemitalo (@KalleOlaviNiemitalo) I think you need to paste more than 100 characters (the length of the
INPUT_RECORDbuffer that was passed toReadConsoleInput) in order to trigger the error. I could reproduce it by pasting the following sequence:😀💘💥👍🎅🦄🍄🌎🚖⚓🚀⌚💣😀💘💥👍🎅🦄🍄🌎🚖⚓🚀⌚💣😀💘💥👍🎅🦄🍄🌎🚖⚓🚀⌚💣😀💘💥👍🎅🦄🍄🌎🚖⚓🚀⌚💣😀💘💥👍🎅🦄🍄🌎🚖⚓🚀⌚💣
amoldeshpande commentedon Dec 27, 2020
I have been using a single 😁 to crash it.
j4james commentedon Dec 27, 2020
In that case I can't reproduce it either. What's the commit hash of the revision that you're testing with? And in case it makes any difference, what are the build details - x86 or x64, debug or release? Also, what keyboard locale are you using?
j4james commentedon Dec 27, 2020
I just realised that the crash that I was seeing was actually in the
DirectReadData::Notifymethod rather than the_DoGetConsoleInputfunction, but the code is essentially identical.This is in
DirectReadData::Notify:terminal/src/host/readDataDirect.cpp
Lines 168 to 184 in d09fdd6
And this is in
_DoGetConsoleInput:terminal/src/host/directio.cpp
Lines 226 to 242 in d09fdd6
Either of those will crash if the number of
readEventsis more than 1 greater than the_eventReadCount, and that is easy to achieve with a multibyte codepage. I can't see how the crash could be triggered with a single character, though, unlessReadConsoleInputwas called with a much smaller record buffer.KalleOlaviNiemitalo commentedon Dec 27, 2020
If I understand correctly, InputBuffer::_ReadBuffer tries to predict how many UTF-16 input events fit in the specified number of OEM input events, but it assumes the OEM encoding uses at most two bytes per character:
terminal/src/host/inputBuffer.cpp
Lines 394 to 405 in d09fdd6
According to #7589 (comment), the estimated number of bytes per character even depends on the font.
Then, SplitToOem translates the UTF-16 input events to OEM input events. If the configured code page is UTF-8, then it uses CESU-8, which may need three bytes per UTF-16 code unit. _DoGetConsoleInput cannot return the excess events to its caller and does not know how to put them back to the input buffer, either.
If InputBuffer::_ReadBuffer supported UTF-8, then that would avoid the crash, I think. However, the resulting input events would still have CESU-8 rather than UTF-8, unless that is converted in some other layer that I cannot find now.
Also, I wonder if the StoreReadPartialByteSequence call should perhaps be skipped if IsPeek is true.
amoldeshpande commentedon Dec 27, 2020
dangit, I can't reproduce it any more with my simple piece of code.
The more involved repro consists of running code in this branch https://github.com/amoldeshpande/tcsh/tree/unicode under Windows Terminal or OpenConsole.exe and pasting the emoji. This is 100% still repro-able with font of "MesloLGM NF" . Have not tried any other fonts IIRC with this shell.
(Nerd Fonts from here https://github.com/ryanoasis/nerd-fonts/releases)
In answer to a previous question, I used an x64 debug build with standard US-EN keyboard layout.
I will keep trying to make my simple repro crash again meanwhile.
j4james commentedon Dec 27, 2020
My guess is that there was a mode change involved somewhere (i.e.
SetConsoleMode) that persisted from another test case or app. Then when you restarted OpenConsole, the modes went back to the defaults, so the error couldn't be reproduced.amoldeshpande commentedon Dec 27, 2020
[-]OpenConsole crash when pasting emoji if SetFileApisToANSI() [/-][+]OpenConsole crash when pasting emoji [/+]20 remaining items
zadjii-msft commentedon Feb 2, 2022
Hmmmmmm. So it sounds like we kinda need to do a
SplitToOeminInputBuffer::Read, before we even move the records to theNotifycall. Or something like a pre-emptive scan inRead, like checking how many events each event will be translated into. I wonder how easy this would be to write a test for...zadjii-msft commentedon Feb 2, 2022
Okay so I think
InputBuffer::Readis only called in two places:directio.cpp:189readDataDirect.cpp:135Both do the same thing. If called with
!unicode, then they will callSplitToOemon the events read from the buffer, to expand them out to chars. So I think it's okay to pre-emptively trim the buffer in the!unicodecase inside ofIB::Read, because we know the caller will be expanding them.Wow those two functions are really basically the same code aren't they...
I think this is a valid test for #8663