wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX and WASI
https://wasmer.io
MIT License
18.88k stars 808 forks source link

The result is different from other wasm runtimes while executing the given wasm file with wasmer #4142

Open luxinyi0105 opened 1 year ago

luxinyi0105 commented 1 year ago

Describe the bug

While executing the given wasm files with wasmer and some other wasm runtimes, such as wasmtime and wasmedge, the results are different.

$ wasmer -vV
wasmer 4.0.0 (6ccf29d 2023-07-24)
binary: wasmer-cli
commit-hash: 6ccf29df1ebab40b3e3e7676ceac7f9deab9a8a3
commit-date: 2023-07-24
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift,llvm
$ rustc -vV
rustc 1.73.0-nightly (0308df23e 2023-07-21)
binary: rustc
commit-hash: 0308df23e621e783e31a27ca5beaa01b9df60d4a
commit-date: 2023-07-21
host: x86_64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Expected behavior

$ wasmer wasm_file_1.wasm

We believe that the "expected behaviour" should be to not output anything.

The reason is that using other wasm runtime tools, such as wasmtime and wasmedge, to execute the same test case results in nothing being output.

Actual behavior

$ wasmer wasm_file_1.wasm
checksum = 0����\�����ih�ih�ih�ih�ih�ih�ih^N�����B�*��D+�\�������^N��������     '�=7���7������� �����v� 7����v�7���v�7���7���'�=        ��������v��v�����������������vP�P��=�~I���P������������wasm_file_1.wasm��-+   0X0x-0X+0X 0X-0x+0x 0xnaninfg_1056[i][j]g_888[i]g_1243[i]NANINFg_1199g_789g_279g_69g_19g_419g_1109g0

Additional context

wasm_file_2.wasm in zip has similar problem, the distinction is that executing it with wasmer only outputs checksum = without any additional garbled code.

Michael-F-Bryan commented 1 year ago

@luxinyi0105 do you have the source code that this program was compiled from? That'll make investigating a lot easier because we can pinpoint which parts of the program introduce the issue.

luxinyi0105 commented 1 year ago

@luxinyi0105 do you have the source code that this program was compiled from? That'll make investigating a lot easier because we can pinpoint which parts of the program introduce the issue.

Thanks for your reply.

For testcase_1, the original C program is c_file_1.c, the compilation results with Emscripten is wasm_file_1.wasm, and its wat format is wat_file_1.wat.

We mutated the wat file to change all lt_s with le_u, and change all lt_u with gt_u. The result after mutation is mutated_file_1.wat, and its wasm format is mutated_file_1.wasm.

$ wasmer wasm_file_1.wasm
checksum = 26F04D2E

$ wasmer mutated_file_1.wasm
checksum = 0����\�����ih�ih�ih�ih�ih�ih�ih^N�����B�*��D+�\�������^N��������     '�=7���7������� �����v� 7����v�7���v�7���7���'�=        ��������v��v�����������������vP�P��=�~I���P������������wasm_file_1.wasm��-+   0X0x-0X+0X 0X-0x+0x 0xnaninfg_1056[i][j]g_888[i]g_1243[i]NANINFg_1199g_789g_279g_69g_19g_419g_1109g0

For testcase_2, the original C program is c_file_2.c, the compilation results with Emscripten is wasm_file_2.wasm, and its wat format is wat_file_2.wat.

We mutated the wat file to change all lt_u with gt_s, and change all le_s with gt_s. The result after mutation is mutated_file_2.wat, and its wasm format is mutated_file_2.wasm.

$ wasmer wasm_file_2.wasm
checksum = 47062B32

$ wasmer mutated_file_2.wasm
checksum = 
stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 month ago

Feel free to reopen the issue if it has been closed by mistake.