From ddf514e99e93a0a85135eec80e6a14eb515019f3 Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Thu, 19 Mar 2026 18:31:04 +0100 Subject: [PATCH] Fix a deadlock during cooked reads (#19994) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #19922 ## Validation Steps Performed * The repro now works as expected ✅ (`CreatePseudoConsole({1,20})` + `WriteFile("キ")`) --- src/host/readDataCooked.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/host/readDataCooked.cpp b/src/host/readDataCooked.cpp index dd3d246645..ee862a03ae 100644 --- a/src/host/readDataCooked.cpp +++ b/src/host/readDataCooked.cpp @@ -1313,6 +1313,15 @@ COOKED_READ_DATA::LayoutResult COOKED_READ_DATA::_layoutLine(std::wstring& outpu til::CoordType cols = 0; const auto len = textBuffer.FitTextIntoColumns(text, columnLimit - column, cols); + // GH#19922: We need to account for terminals that are just 1 column wide, as we may deadlock otherwise. + // `columnLimit - column == 1` will then prevent `FitTextIntoColumns` from fitting any wide glyphs. + // We can detect this by checking for `len == 0`, skip the offending glyph and break out of the deadlock. + if (len == 0) [[unlikely]] + { + it += textBuffer.GraphemeNext(text, 0); + break; + } + output.append(text, 0, len); column += cols; it += len;