From 5d637fd0ecf40e8ceb6e9dc8b44fd472da3ddd87 Mon Sep 17 00:00:00 2001 From: rabindra789 Date: Sat, 11 Jul 2026 18:57:22 +0530 Subject: [PATCH] std: increase Windows console stdin scratch buffer The small-buffer path in Stdin::read allocates a one-element UTF-16 scratch buffer. When a pending surrogate exists, read_u16s_fixup_surrogates requires temporary storage for both the buffered surrogate and one newly read UTF-16 code unit. Increase the scratch buffer to two UTF-16 code units so the surrogate path can complete without panicking. --- library/std/src/sys/stdio/windows.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/stdio/windows.rs b/library/std/src/sys/stdio/windows.rs index 475a0592528b4..89976847d3817 100644 --- a/library/std/src/sys/stdio/windows.rs +++ b/library/std/src/sys/stdio/windows.rs @@ -278,7 +278,7 @@ impl io::Read for Stdin { Ok(bytes_copied) } else if buf.len() - bytes_copied < 4 { // Not enough space to get a UTF-8 byte. We will use the incomplete UTF8. - let mut utf16_buf = [MaybeUninit::new(0); 1]; + let mut utf16_buf = [MaybeUninit::new(0); 2]; // Read one u16 character. let read = read_u16s_fixup_surrogates(handle, &mut utf16_buf, 1, &mut self.surrogate)?; // Read bytes, using the (now-empty) self.incomplete_utf8 as extra space.