https://github.com/python/cpython/commit/8b898f5ed79aae1654047410f27df25028879a0f commit: 8b898f5ed79aae1654047410f27df25028879a0f branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: cmaloney <[email protected]> date: 2026-11-17T12:46:35-08:00 summary:
[3.15] gh-158414: Fix hang when writing incomplete UTF-8 sequence to Windows console (GH-158435) (#162168) gh-158414: Fix hang when writing incomplete UTF-8 sequence to Windows console (GH-158435) (cherry picked from commit aedb2c1d3d2bfaf60cef84c549606cc08542b63c) Co-authored-by: An Long <[email protected]> Co-authored-by: Cody Maloney <[email protected]> files: A Misc/NEWS.d/next/Windows/2026-09-30-01-12-58.gh-issue-158414.738yJa.rst M Lib/test/test_io/test_winconsoleio.py M Modules/_io/winconsoleio.c diff --git a/Lib/test/test_io/test_winconsoleio.py b/Lib/test/test_io/test_winconsoleio.py index 1bae884ed9ae3ea..b2474007da98935 100644 --- a/Lib/test/test_io/test_winconsoleio.py +++ b/Lib/test/test_io/test_winconsoleio.py @@ -160,7 +160,7 @@ def test_write(self): testcases.append(data + b'\xff') # incomplete multibyte sequence with self.subTest(data=data): - self.assertEqual(f.write(data), len(a)) + self.assertEqual(f.write(data), len(a or data)) for data in testcases: with self.subTest(data=data): self.assertEqual(f.write(data), len(data)) diff --git a/Misc/NEWS.d/next/Windows/2026-09-30-01-12-58.gh-issue-158414.738yJa.rst b/Misc/NEWS.d/next/Windows/2026-09-30-01-12-58.gh-issue-158414.738yJa.rst new file mode 100644 index 000000000000000..dba12665deddd93 --- /dev/null +++ b/Misc/NEWS.d/next/Windows/2026-09-30-01-12-58.gh-issue-158414.738yJa.rst @@ -0,0 +1 @@ +Fix a hang when writing an incomplete UTF-8 sequence to the Windows console. diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c index f9d661fb3071785..0dd0d808dac792d 100644 --- a/Modules/_io/winconsoleio.c +++ b/Modules/_io/winconsoleio.c @@ -1104,7 +1104,10 @@ _io__WindowsConsoleIO_write_impl(winconsoleio *self, PyTypeObject *cls, len = Py_MIN(len, max_wlen * 3); while (1) { /* Fix for github issues gh-110913 and gh-82052. */ - len = _find_last_utf8_boundary(b->buf, len); + DWORD boundary = _find_last_utf8_boundary(b->buf, len); + if (boundary != 0) { + len = boundary; + } wlen = MultiByteToWideChar(CP_UTF8, 0, b->buf, len, NULL, 0); if (wlen <= max_wlen) { break; _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
