Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d114694

Browse files
committed
Reject byte if it cannot start a valid UTF-8 sequence.
1 parent 0202273 commit d114694

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

library/std/src/sys/windows/stdio.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ fn write(
128128
let utf8 = match str::from_utf8(&data[..len]) {
129129
Ok(s) => s,
130130
Err(ref e) if e.valid_up_to() == 0 => {
131-
if data.len() < utf8_char_width(data[0]) {
131+
first_byte_char_width = utf8_char_width(data[0]);
132+
if first_byte_char_width > 1 && data.len() < first_byte_char_width {
132133
incomplete_utf8.bytes[0] = data[0];
133134
incomplete_utf8.len = 1;
134135
return Ok(1);

0 commit comments

Comments
 (0)