Skip to content

Commit 6e57865

Browse files
committed
Add an overflow check
The check will be removed when rust-lang/rust#63326 is fixed
1 parent 0684e88 commit 6e57865

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/hostcalls_impl/fs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ pub(crate) fn fd_allocate(
440440

441441
let current_size = metadata.len();
442442
let wanted_size = offset.checked_add(len).ok_or(host::__WASI_E2BIG)?;
443+
// This check will be unnecessary when rust-lang/rust#63326 is fixed
443444
if wanted_size > i64::max_value() as u64 {
444445
return Err(host::__WASI_E2BIG);
445446
}
@@ -779,6 +780,10 @@ pub(crate) fn fd_filestat_set_size(
779780
.and_then(|fe| fe.fd_object.descriptor.as_file())?;
780781

781782
let st_size = dec_filesize(st_size);
783+
// This check will be unnecessary when rust-lang/rust#63326 is fixed
784+
if st_size > i64::max_value() as u64 {
785+
return Err(host::__WASI_E2BIG);
786+
}
782787
fd.set_len(st_size).map_err(errno_from_ioerror)
783788
}
784789

0 commit comments

Comments
 (0)