whitequark opened Issue #2009:
Consider the following program:
#include <fstream> int main() { std::ofstream ff; ff.open("test.txt", std::ofstream::trunc); ff << "bad bad bad bad\n"; return 0; }
I've attached it here: bad.zip
Open
test.txt
and put something like this there:bad bad bad bad this will remain here
Run it:
wasmtime run --dir . bad.wasm
The file is not truncated.
whitequark labeled Issue #2009:
Consider the following program:
#include <fstream> int main() { std::ofstream ff; ff.open("test.txt", std::ofstream::trunc); ff << "bad bad bad bad\n"; return 0; }
I've attached it here: bad.zip
Open
test.txt
and put something like this there:bad bad bad bad this will remain here
Run it:
wasmtime run --dir . bad.wasm
The file is not truncated.
whitequark edited Issue #2009:
Consider the following program:
#include <fstream> int main() { std::ofstream ff; ff.open("test.txt", std::ofstream::trunc); ff << "bad bad bad bad\n"; return 0; }
I've attached it here: bad.zip
Open
test.txt
and put something like this there:bad bad bad bad this will remain here
Run it:
wasmtime run --dir . bad.wasm
The file is not truncated.
whitequark commented on Issue #2009:
Here's the WASI call log:
DEBUG wasi_common::ctx > WasiCtx inserting entry PendingEntry::Thunk(0x32cde8) DEBUG wasi_common::ctx > WasiCtx inserted at Fd(0) DEBUG wasi_common::ctx > WasiCtx inserting entry PendingEntry::Thunk(0x32cde8) DEBUG wasi_common::ctx > WasiCtx inserted at Fd(1) DEBUG wasi_common::ctx > WasiCtx inserting entry PendingEntry::Thunk(0x32cde8) DEBUG wasi_common::ctx > WasiCtx inserted at Fd(2) DEBUG wasi_common::ctx > WasiCtx inserted at Fd(3) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx inserting (0, Some(PendingEntry::Thunk(0x32d058))) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx inserting (1, Some(PendingEntry::Thunk(0x32d068))) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx inserting (2, Some(PendingEntry::Thunk(0x32d078))) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx inserting (3, Entry { file_type: 3, descriptor: OsHandle(OsHandle(File { handle: 0x5c, path: "\\\\?\\Z:\\home\\whitequark\\xxx\\build" })), rights_base: 264240858, rights_inheriting: 268435455, preopen_path: Some(".") }) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx entries = {0: Entry { file_type: 2, descriptor: Stdin, rights_base: 136314954, rights_inheriting: 136314954, preopen_path: None }, 3: Entry { file_type: 3, descriptor: OsHandle(OsHandle(File { handle: 0x5c, path: "\\\\?\\Z:\\home\\whitequark\\xxx\\build" })), rights_base: 264240858, rights_inheriting: 268435455, preopen_path: Some(".") }, 1: Entry { file_type: 2, descriptor: Stdout, rights_base: 136314954, rights_inheriting: 136314954, preopen_path: None }, 2: Entry { file_type: 2, descriptor: Stderr, rights_base: 136314954, rights_inheriting: 136314954, preopen_path: None }} TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_prestat_get" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(3) TRACE wasi_common::wasi::wasi_snapshot_preview1 > buf=Dir(PrestatDir { pr_name_len: 1 }) TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_prestat_dir_name" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(3) path=*guest 0x20010 path_len=1 TRACE wasi_common::snapshots::wasi_snapshot_preview1 > | path='.' TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_prestat_get" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(4) TRACE wasi_common::wasi::wasi_snapshot_preview1 > error=Badf TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_fdstat_get" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(3) TRACE wasi_common::wasi::wasi_snapshot_preview1 > stat=Fdstat { fs_filetype: Directory, fs_flags: Fdflags(0), fs_rights_base: Rights(264240858), fs_rights_inheriting: Rights(268435455) } TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="path_open" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(3) dirflags=symlink_follow (0x1) path=*guest 0x400/8 oflags=creat|trunc (0x9) fs_rights_base=fd_datasync|fd_seek|fd_fdstat_set_flags|fd_sync|fd_tell|fd_write|fd_advise|fd_allocate|path_create_directory|path_create_file|path_link_source|path_link_target|path_open|path_readlink|path_rename_source|path_rename_target|path_filestat_get|path_filestat_set_size|path_filestat_set_times|fd_filestat_get|fd_filestat_set_size|fd_filestat_set_times|path_symlink|path_remove_directory|path_unlink_file|poll_fd_readwrite (0xfffbffd) fs_rights_inherting=fd_datasync|fd_read|fd_seek|fd_fdstat_set_flags|fd_sync|fd_tell|fd_write|fd_advise|fd_allocate|path_create_directory|path_create_file|path_link_source|path_link_target|path_open|fd_readdir|path_readlink|path_rename_source|path_rename_target|path_filestat_get|path_filestat_set_size|path_filestat_set_times|fd_filestat_get|fd_filestat_set_size|fd_filestat_set_times|path_symlink|path_remove_directory|path_unlink_file|poll_fd_readwrite (0xfffffff) fdflags=empty (0x0) TRACE wasi_common::snapshots::wasi_snapshot_preview1 > | needed_rights=HandleRights { base: path_create_file|path_open (0x2400), inheriting: fd_datasync|fd_read|fd_seek|fd_fdstat_set_flags|fd_sync|fd_tell|fd_write|fd_advise|fd_allocate|path_create_directory|path_create_file|path_link_source|path_link_target|path_open|fd_readdir|path_readlink|path_rename_source|path_rename_target|path_filestat_get|path_filestat_set_size|path_filestat_set_times|fd_filestat_get|fd_filestat_set_size|fd_filestat_set_times|path_symlink|path_remove_directory|path_unlink_file|poll_fd_readwrite (0xfffffff) } TRACE wasi_common::path > | (path_ptr,path_len)='test.txt' DEBUG wasi_common::path > path_get cur_path = "test.txt" DEBUG wasi_common::path > path_get path_stack = [] DEBUG wasi_common::sys::windows::path > out_path="Z:\\home\\whitequark\\xxx\\build\\test.txt" DEBUG wasi_common::sys::windows::path > readlinkat error=50 TRACE wasi_common::snapshots::wasi_snapshot_preview1 > | calling path_open impl: read=false, write=true DEBUG wasi_common::sys::windows::path > out_path="Z:\\home\\whitequark\\xxx\\build\\test.txt" DEBUG wasi_common::sys > Created new instance of OsFile: OsFile { rights: Cell { value: HandleRights { base: Rights(148898303), inheriting: Rights(0) } }, handle: RawOsHandle(Cell { value: 0x64 }) } TRACE wasi_common::wasi::wasi_snapshot_preview1 > opened_fd=Fd(4) TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_fdstat_get" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(4) TRACE wasi_common::wasi::wasi_snapshot_preview1 > stat=Fdstat { fs_filetype: RegularFile, fs_flags: Fdflags(0), fs_rights_base: Rights(148898301), fs_rights_inheriting: Rights(0) } TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_write" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(4) iovs=*guest 0x150b0/2 TRACE wasi_common::wasi::wasi_snapshot_preview1 > nwritten=16 TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_close" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(4) TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0))
whitequark edited a comment on Issue #2009:
Here's the WASI call log (this is on wine, but I'm triaging a bug report from someone who hits it on Windows):
DEBUG wasi_common::ctx > WasiCtx inserting entry PendingEntry::Thunk(0x32cde8) DEBUG wasi_common::ctx > WasiCtx inserted at Fd(0) DEBUG wasi_common::ctx > WasiCtx inserting entry PendingEntry::Thunk(0x32cde8) DEBUG wasi_common::ctx > WasiCtx inserted at Fd(1) DEBUG wasi_common::ctx > WasiCtx inserting entry PendingEntry::Thunk(0x32cde8) DEBUG wasi_common::ctx > WasiCtx inserted at Fd(2) DEBUG wasi_common::ctx > WasiCtx inserted at Fd(3) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx inserting (0, Some(PendingEntry::Thunk(0x32d058))) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx inserting (1, Some(PendingEntry::Thunk(0x32d068))) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx inserting (2, Some(PendingEntry::Thunk(0x32d078))) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx inserting (3, Entry { file_type: 3, descriptor: OsHandle(OsHandle(File { handle: 0x5c, path: "\\\\?\\Z:\\home\\whitequark\\xxx\\build" })), rights_base: 264240858, rights_inheriting: 268435455, preopen_path: Some(".") }) DEBUG wasi_common::old::snapshot_0::ctx > WasiCtx entries = {0: Entry { file_type: 2, descriptor: Stdin, rights_base: 136314954, rights_inheriting: 136314954, preopen_path: None }, 3: Entry { file_type: 3, descriptor: OsHandle(OsHandle(File { handle: 0x5c, path: "\\\\?\\Z:\\home\\whitequark\\xxx\\build" })), rights_base: 264240858, rights_inheriting: 268435455, preopen_path: Some(".") }, 1: Entry { file_type: 2, descriptor: Stdout, rights_base: 136314954, rights_inheriting: 136314954, preopen_path: None }, 2: Entry { file_type: 2, descriptor: Stderr, rights_base: 136314954, rights_inheriting: 136314954, preopen_path: None }} TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_prestat_get" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(3) TRACE wasi_common::wasi::wasi_snapshot_preview1 > buf=Dir(PrestatDir { pr_name_len: 1 }) TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_prestat_dir_name" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(3) path=*guest 0x20010 path_len=1 TRACE wasi_common::snapshots::wasi_snapshot_preview1 > | path='.' TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_prestat_get" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(4) TRACE wasi_common::wasi::wasi_snapshot_preview1 > error=Badf TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_fdstat_get" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(3) TRACE wasi_common::wasi::wasi_snapshot_preview1 > stat=Fdstat { fs_filetype: Directory, fs_flags: Fdflags(0), fs_rights_base: Rights(264240858), fs_rights_inheriting: Rights(268435455) } TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="path_open" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(3) dirflags=symlink_follow (0x1) path=*guest 0x400/8 oflags=creat|trunc (0x9) fs_rights_base=fd_datasync|fd_seek|fd_fdstat_set_flags|fd_sync|fd_tell|fd_write|fd_advise|fd_allocate|path_create_directory|path_create_file|path_link_source|path_link_target|path_open|path_readlink|path_rename_source|path_rename_target|path_filestat_get|path_filestat_set_size|path_filestat_set_times|fd_filestat_get|fd_filestat_set_size|fd_filestat_set_times|path_symlink|path_remove_directory|path_unlink_file|poll_fd_readwrite (0xfffbffd) fs_rights_inherting=fd_datasync|fd_read|fd_seek|fd_fdstat_set_flags|fd_sync|fd_tell|fd_write|fd_advise|fd_allocate|path_create_directory|path_create_file|path_link_source|path_link_target|path_open|fd_readdir|path_readlink|path_rename_source|path_rename_target|path_filestat_get|path_filestat_set_size|path_filestat_set_times|fd_filestat_get|fd_filestat_set_size|fd_filestat_set_times|path_symlink|path_remove_directory|path_unlink_file|poll_fd_readwrite (0xfffffff) fdflags=empty (0x0) TRACE wasi_common::snapshots::wasi_snapshot_preview1 > | needed_rights=HandleRights { base: path_create_file|path_open (0x2400), inheriting: fd_datasync|fd_read|fd_seek|fd_fdstat_set_flags|fd_sync|fd_tell|fd_write|fd_advise|fd_allocate|path_create_directory|path_create_file|path_link_source|path_link_target|path_open|fd_readdir|path_readlink|path_rename_source|path_rename_target|path_filestat_get|path_filestat_set_size|path_filestat_set_times|fd_filestat_get|fd_filestat_set_size|fd_filestat_set_times|path_symlink|path_remove_directory|path_unlink_file|poll_fd_readwrite (0xfffffff) } TRACE wasi_common::path > | (path_ptr,path_len)='test.txt' DEBUG wasi_common::path > path_get cur_path = "test.txt" DEBUG wasi_common::path > path_get path_stack = [] DEBUG wasi_common::sys::windows::path > out_path="Z:\\home\\whitequark\\xxx\\build\\test.txt" DEBUG wasi_common::sys::windows::path > readlinkat error=50 TRACE wasi_common::snapshots::wasi_snapshot_preview1 > | calling path_open impl: read=false, write=true DEBUG wasi_common::sys::windows::path > out_path="Z:\\home\\whitequark\\xxx\\build\\test.txt" DEBUG wasi_common::sys > Created new instance of OsFile: OsFile { rights: Cell { value: HandleRights { base: Rights(148898303), inheriting: Rights(0) } }, handle: RawOsHandle(Cell { value: 0x64 }) } TRACE wasi_common::wasi::wasi_snapshot_preview1 > opened_fd=Fd(4) TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_fdstat_get" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(4) TRACE wasi_common::wasi::wasi_snapshot_preview1 > stat=Fdstat { fs_filetype: RegularFile, fs_flags: Fdflags(0), fs_rights_base: Rights(148898301), fs_rights_inheriting: Rights(0) } TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_write" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(4) iovs=*guest 0x150b0/2 TRACE wasi_common::wasi::wasi_snapshot_preview1 > nwritten=16 TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0)) TRACE wasi_common::wasi::wasi_snapshot_preview1 > wiggle abi; module="wasi_snapshot_preview1" function="fd_close" TRACE wasi_common::wasi::wasi_snapshot_preview1 > fd=Fd(4) TRACE wasi_common::wasi::wasi_snapshot_preview1 > success=No error occurred. System call completed successfully. (Errno::Success(0))
peterhuene commented on Issue #2009:
An oflag of
CREAT | TRUNC
should result in a creation disposition flag ofCREATE_ALWAYS
. That would normally be truncating the file if we were using the Windows API directly.However, I think the problem lies here where we're converting the Windows disposition flag to a Rust
OpenOptions
. That should probably have atruncate(true)
on it.
peterhuene labeled Issue #2009:
Consider the following program:
#include <fstream> int main() { std::ofstream ff; ff.open("test.txt", std::ofstream::trunc); ff << "bad bad bad bad\n"; return 0; }
I've attached it here: bad.zip
Open
test.txt
and put something like this there:bad bad bad bad this will remain here
Run it:
wasmtime run --dir . bad.wasm
The file is not truncated.
peterhuene labeled Issue #2009:
Consider the following program:
#include <fstream> int main() { std::ofstream ff; ff.open("test.txt", std::ofstream::trunc); ff << "bad bad bad bad\n"; return 0; }
I've attached it here: bad.zip
Open
test.txt
and put something like this there:bad bad bad bad this will remain here
Run it:
wasmtime run --dir . bad.wasm
The file is not truncated.
github-actions[bot] commented on Issue #2009:
Subscribe to Label Action
cc @kubkon
<details>
This issue or pull request has been labeled: "wasi"Thus the following users have been cc'd because of the following labels:
- kubkon: wasi
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
whitequark commented on Issue #2009:
However, I think the problem lies here where we're converting the Windows disposition flag to a Rust
OpenOptions
. That should probably have atruncate(true)
on it.Nope, that code doesn't even run (I put a panic in it).
whitequark commented on Issue #2009:
Sorry, I forgot a
--dir .
and the application silently crashed (because-fno-exceptions
...). I can confirm that this fixes the bug.
peterhuene closed Issue #2009:
Consider the following program:
#include <fstream> int main() { std::ofstream ff; ff.open("test.txt", std::ofstream::trunc); ff << "bad bad bad bad\n"; return 0; }
I've attached it here: bad.zip
Open
test.txt
and put something like this there:bad bad bad bad this will remain here
Run it:
wasmtime run --dir . bad.wasm
The file is not truncated.
Last updated: Nov 22 2024 at 17:03 UTC