You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Different result from other wasm runtimes while executing the given wasm file #6919
The given testcase was simply mutated a wasm file, which was obtained by compiling C program generated with Csmith using Emscripten Compiler(Emcc).
The original C program is c_file.c, the compilation results with Emscripten is wasm_file.wasm, and its wat format is wat_file.wat.
We mutated the wat file to change its global.set 0 in line 7627 with local.set 0. The result after mutation is mutated_file.wat, and its wasm format is mutated_file.wasm.
Expected Results
$ wasmtime mutated_file.wasm
checksum = 61D81D2D
Actual Results
$ wasmedge mutated_file.wasm
checksum = 61D81D2D
Error: failed to run main module `mutated_file.wasm`
Caused by:
0: failed to invoke command default
1: error while executing at wasm backtrace:
0: 0x53b2 - <unknown>!<wasm function22>
1: 0x53aa - <unknown>!<wasm function21>
2: 0x50e3 - <unknown>!<wasm function16>
2: exit with invalid exit status outside of [0..126)
Versions and Environment
Wasmtime version or commit: wasmtime-cli 13.0.0
Operating system: Ubuntu 22.04.1
Architecture: x86_64
Extra Info
I tried to use some other wasm runtimes, such as wasmer, wasmedge and wasm-micro-runtime(WAMR) to execute the same testcase, they just output the checksum result and do not trigger errors.
It seems that there is something wrong with the “exception handling module”, but I am not sure if the problem lies in wasmtime or other runtime tools due to a lack of understanding of WebAssembly. So the details still need you to confirm. Thanks a lot!
Thanks for the report, but I don't think there's a problem here on our side. The mutated instruction is changing the return value of the function to something totally different, and this function is the main function. This means that main's return value, which was previously 0, is now something totally different. That gets threaded through to proc_exit which has the requirement that the exit status is in the printed range, which presumably the provided status isn't.
My guess is that other runtimes are not validating the exit status at all. Wasmtime does that for portability and platform compatibility and other runtimes may eschew this. The current documentation for proc_exit does not exactly specify what to do here. I can't currently easily find the PR that introduced that condition, but I believe it's been around for awhile in Wasmtime.
If you're curious to push on this further I'd recommend opening an issue with WASI to clarify whether this behavior is still desired and/or should be codified in the documentation. If not we should remove it in Wasmtime. If so other runtimes should be updated.
Activity
alexcrichton commentedon Aug 28, 2023
Thanks for the report, but I don't think there's a problem here on our side. The mutated instruction is changing the return value of the function to something totally different, and this function is the
mainfunction. This means thatmain's return value, which was previously 0, is now something totally different. That gets threaded through toproc_exitwhich has the requirement that the exit status is in the printed range, which presumably the provided status isn't.My guess is that other runtimes are not validating the exit status at all. Wasmtime does that for portability and platform compatibility and other runtimes may eschew this. The current documentation for
proc_exitdoes not exactly specify what to do here. I can't currently easily find the PR that introduced that condition, but I believe it's been around for awhile in Wasmtime.If you're curious to push on this further I'd recommend opening an issue with WASI to clarify whether this behavior is still desired and/or should be codified in the documentation. If not we should remove it in Wasmtime. If so other runtimes should be updated.