-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Description
Environment
Windows build number: Version 10.0.18362.535
Steps to reproduce
Compile and run the following C program in a conhost shell:
#include <windows.h>
void main() {
SetConsoleOutputCP(50220);
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD written;
FillConsoleOutputCharacterA(handle, 14, 1, COORD{ 0,0 }, &written);
}Expected behavior
I believe codepoint 14 is invalid in the given codepage, so I would expect it to write out something like the unicode replacement character in the top left corner of the screen buffer, or possibly nothing at all. The legacy console seems to write out a null character.
Actual behavior
The conhost crashes.
What's happening is that the FillConsoleOutputCharacterAImpl method is calling ConvertToW with a string that can't be converted in the given codepage. And ConvertToW then throws an exception when MultiByteToWideChar returns 0.
terminal/src/types/convert.cpp
Lines 41 to 42 in 9e5792b
| int const iTarget = MultiByteToWideChar(codePage, 0, source.data(), iSource, nullptr, 0); | |
| THROW_LAST_ERROR_IF(0 == iTarget); |
And note that FillConsoleOutputCharacterAImpl is declared as noexcept, even though it quite clearly is capable of throwing exceptions. I've actually noticed a few cases like that - we may need to do an audit of our noexcept usage, and make sure it's being applied appropriately.