Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix size computation for pwrite #4942

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/wasix/src/syscalls/wasi/fd_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ pub(crate) fn fd_write_internal<M: MemorySize>(

// reborrow and update the size
if !is_stdio {
let offset = if is_file && should_update_cursor {
let curr_offset = if is_file && should_update_cursor {
let bytes_written = bytes_written as u64;
let mut fd_map = state.fs.fd_map.write().unwrap();
let fd_entry = wasi_try_ok_ok!(fd_map.get_mut(&fd).ok_or(Errno::Badf));
Expand All @@ -433,10 +433,14 @@ pub(crate) fn fd_write_internal<M: MemorySize>(
unsafe { env.get_memory_and_wasi_state_and_inodes(&ctx, 0) };
if is_file {
let mut stat = fd_entry.inode.stat.write().unwrap();
// If we wrote before the end, the current size is still correct.
// Otherwise, we only got as far as the current cursor. So, the
// max of the two is the correct new size.
stat.st_size = stat.st_size.max(offset);
if should_update_cursor {
// If we wrote before the end, the current size is still correct.
// Otherwise, we only got as far as the current cursor. So, the
// max of the two is the correct new size.
stat.st_size = stat.st_size.max(curr_offset);
} else {
stat.st_size = stat.st_size.max(offset + bytes_written as u64);
}
} else {
// Cast is valid because we don't support 128 bit systems...
fd_entry.inode.stat.write().unwrap().st_size += bytes_written as u64;
Expand Down
Loading