Skip to content
Merged
Prev Previous commit
Next Next commit
Reject byte if it cannot start a valid UTF-8 sequence.
  • Loading branch information
Count-Count committed Mar 24, 2021
commit d11469404274c7162b295105846f98111bc273ab
3 changes: 2 additions & 1 deletion library/std/src/sys/windows/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ fn write(
let utf8 = match str::from_utf8(&data[..len]) {
Ok(s) => s,
Err(ref e) if e.valid_up_to() == 0 => {
if data.len() < utf8_char_width(data[0]) {
first_byte_char_width = utf8_char_width(data[0]);
if first_byte_char_width > 1 && data.len() < first_byte_char_width {
incomplete_utf8.bytes[0] = data[0];
incomplete_utf8.len = 1;
return Ok(1);
Expand Down