Skip to content

Commit bb661f2

Browse files
lf-mgattozzi
authored andcommitted
Fix unsoundness on invalid utf-8 inputs
Previously, unchecked user input bytes were passed into `str::from_utf8_unchecked`, which is unsound as it was within a safe function. It's been revised to check the user input and fail if there's invalid input.
1 parent 0e1ecba commit bb661f2

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ where
9191
let mut write_buffer = SmallVec::<[u8; BUFSIZE]>::new();
9292

9393
// Let textwrap work its magic
94-
let wrapped = fill(unsafe { str::from_utf8_unchecked(input) }, max_width);
94+
let wrapped = fill(
95+
str::from_utf8(input).map_err(|_| std::io::ErrorKind::InvalidData)?,
96+
max_width,
97+
);
9598

9699
let lines: Vec<&str> = wrapped.lines().collect();
97100

0 commit comments

Comments
 (0)