Only honor Ctrl+Z during ReadFile if the console is in PROCESSED mode (#19940)

This restores the behavior of ReadFile to that of Windows 7.

Closes #4958

(cherry picked from commit 80e4b3c947)
Service-Card-Id: PVTI_lADOAF3p4s4BQX0-zgpBM28
Service-Version: 1.25
This commit is contained in:
Dustin L. Howett
2026-03-11 11:52:33 -05:00
committed by Dustin L. Howett
parent e382d328b2
commit 2c9277cbb4
3 changed files with 12 additions and 1 deletions

View File

@@ -572,6 +572,7 @@ FGHIJ
fgidx
FGs
FILEDESCRIPTION
filehops
FILESUBTYPE
FILESYSPATH
FILEW

View File

@@ -670,7 +670,7 @@ void FileTests::TestReadFileBasicEmpty()
const auto hIn = GetStdInputHandle();
VERIFY_IS_NOT_NULL(hIn, L"Verify we have the standard input handle.");
DWORD dwMode = 0;
DWORD dwMode = ENABLE_PROCESSED_INPUT; // ^Z is only handled when processed input is enabled.
VERIFY_WIN32_BOOL_SUCCEEDED(SetConsoleMode(hIn, dwMode), L"Set input mode for test.");
VERIFY_WIN32_BOOL_SUCCEEDED(FlushConsoleInputBuffer(hIn), L"Flush input buffer in preparation for test.");

View File

@@ -270,6 +270,16 @@ constexpr T saturate(auto val)
}
CATCH_RETURN();
if (a->ProcessControlZ)
{
// ProcessControlZ is only set for CONSOLE_IO_RAW_READ. To restore
// the behavior from Windows 7 (see filehops.c:123) we need to honor
// ^Z only if PROCESSED_INPUT is enabled.
ULONG InputMode{ 0 };
m->_pApiRoutines->GetConsoleInputModeImpl(*pInputBuffer, InputMode);
a->ProcessControlZ = (InputMode & ENABLE_PROCESSED_INPUT) != 0;
}
TraceConsoleAPICallWithOrigin(
"ReadConsole",
TraceLoggingBoolean(a->Unicode, "Unicode"),