Skip to content

Commit 83bf8cf

Browse files
authored
Merge pull request #155 from ThomasHabets/safe-128
Future proof `validate_len()` for 128bit
2 parents 7e839b9 + 5f753ab commit 83bf8cf

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,13 @@ impl MmapOptions {
250250
// This is not a problem on 64-bit targets, but on 32-bit one
251251
// having a file or an anonymous mapping larger than 2GB is quite normal
252252
// and we have to prevent it.
253-
//
254-
// The code below is essentially the same as in Rust's std:
255-
// https://github.com/rust-lang/rust/blob/db78ab70a88a0a5e89031d7ee4eccec835dcdbde/library/alloc/src/raw_vec.rs#L495
256-
if len > isize::MAX as u64 {
253+
if isize::try_from(len).is_err() {
257254
return Err(Error::new(
258255
ErrorKind::InvalidData,
259256
"memory map length overflows isize",
260257
));
261258
}
262-
259+
// If an unsigned number (u64) fits in isize, then it fits in usize.
263260
Ok(len as usize)
264261
}
265262

0 commit comments

Comments
 (0)