Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c72c762

Browse files
committed
fix(lib-std-fs): handle usize overflow in read_to_string
1 parent 175e043 commit c72c762

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

‎library/std/src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ pub fn read<P: AsRef<Path>>(path: P) -> io::Result<Vec<u8>> {
346346
pub fn read_to_string<P: AsRef<Path>>(path: P) -> io::Result<String> {
347347
fn inner(path: &Path) -> io::Result<String> {
348348
let mut file = File::open(path)?;
349-
let size = file.metadata().map(|m| m.len()asusize).ok();
349+
let size = file.metadata().map(|m| usize::try_from(m.len()).unwrap_or(usize::MAX)).ok();
350350
let mut string = String::new();
351351
string.try_reserve_exact(size.unwrap_or(0))?;
352352
io::default_read_to_string(&mut file, &mut string, size)?;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /