WasmEdge icon indicating copy to clipboard operation
WasmEdge copied to clipboard

bug: Different error report when running a same binary

Open XinyuShe opened this issue 1 year ago • 1 comments
trafficstars

Summary

I randomly generated a wasm binary and tested it in AOT mode with different runtimes. I found that Wasmedge produced different error messages compared to other runtimes. Furthermore, I also tested Wasmedge in JIT mode, and the error messages were different from those in AOT mode. Therefore, I suspect this may be a bug. filea9.zip

Current State

root@4252f5ec38df:/a# wasmedge_0.13.5 compile filea9.wasm filea9.so
[2023-11-27 00:33:46.125] [info] compile start
[2023-11-27 00:33:46.180] [info] verify start
[2023-11-27 00:33:46.211] [info] optimize start
[2023-11-27 00:33:47.325] [info] codegen start
[2023-11-27 00:33:48.322] [info] output start
[2023-11-27 00:33:48.335] [info] compile done
root@4252f5ec38df:a# wasmedge_0.13.5 --reactor filea9.so main
[2023-11-27 00:34:11/.174] [error] execution failed: integer divide by zero, Code: 0x84
[2023-11-27 00:34:11.174] [error]     When executing function name: "main"
root@4252f5ec38df:/a# ./wasmtime_14.0.4 compile  filea9.wasm -o filea9.cwasm
root@4252f5ec38df:/a# ./wasmtime_14.0.4 --allow-precompiled --invoke main filea9.cwasm
Error: failed to run main module `filea9.cwasm`

Caused by:
    0: failed to invoke `main`
    1: error while executing at wasm backtrace:
           0: 0x399b4 - <unknown>!<wasm function 951>
           1: 0x39bfe - <unknown>!<wasm function 952>
           2: 0x3b030 - <unknown>!<wasm function 969>
           3: 0x3b1ac - <unknown>!<wasm function 970>
           4: 0x3b333 - <unknown>!<wasm function 973>
           5: 0x3e19d - <unknown>!<wasm function 1003>
           6: 0x3e71b - <unknown>!<wasm function 1005>
    2: memory fault at wasm address 0x100001d29 in linear memory of size 0x100000000
    3: wasm trap: out of bounds memory access
root@4252f5ec38df:/a# wasmer compile  filea9.wasm  -o filea9.wasmu --enable-simd
Compiler: cranelift
Target: x86_64-unknown-linux-gnu
✔ File compiled successfully to `filea9.wasmu`.
root@4252f5ec38df:a# wasmer run -i main filea9.wasmu 
error: failed to run `filea9.wasmu`
╰─▶ 1: RuntimeError: out of bounds memory access
           at <unnamed> (/a/filea9.wasm[951]:0x399b4)
           at <unnamed> (/a/filea9.wasm[952]:0x39bfe)
           at <unnamed> (/a/filea9.wasm[969]:0x3b030)
           at <unnamed> (/a/filea9.wasm[970]:0x3b1ac)
           at <unnamed> (/a/filea9.wasm[973]:0x3b333)
           at <unnamed> (/a/filea9.wasm[1003]:0x3e19d)
           at <unnamed> (/a/filea9.wasm[1005]:0x3e71b)
root@4252f5ec38df:/a# wasmedge_0.13.5 --reactor filea9.wasm main
[2023-11-27 00:48:00.811] [error] execution failed: out of bounds memory access, Code: 0x88
[2023-11-27 00:48:00.812] [error]     Accessing offset from: 0x100001d29 to: 0x100001d2a , Out of boundary: 0xffffffff
[2023-11-27 00:48:00.812] [error]     In instruction: i32.load16_u (0x2f) , Bytecode offset: 0x000399b4
[2023-11-27 00:48:00.812] [error]     When executing function name: "main"

Expected State

wasmedge report out of bounds memory access instead of integer divide by zero

Reproduction steps

wasmedge_0.13.5 compile filea9.wasm filea9.so
wasmedge_0.13.5 --reactor filea9.so main
wasmtime_14.0.4 compile  filea9.wasm -o filea9.cwasm
wasmtime_14.0.4 --allow-precompiled --invoke main filea9.cwasm
wasmer compile  filea9.wasm  -o filea9.wasmu --enable-simd
wasmer run -i main filea9.wasmu 

Screenshots

No response

Any logs you want to share for showing the specific issue

No response

Components

CLI

WasmEdge Version or Commit you used

WasmEdge-0.13.5-ubuntu20.04_x86_64.tar.gz

Operating system information

Docker version 24.0.5, build ced0996

Hardware Architecture

Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-79-generic x86_64)

Compiler flags and options

No response

XinyuShe avatar Nov 27 '23 08:11 XinyuShe

WasmEdge has no JIT mode yet, but interpreter mode, though JIT is recent plan.

dannypsnl avatar Nov 27 '23 11:11 dannypsnl

Cannot reproduce now on current master (0.14.0-rc.4).

Interpreter:

$ ./wasmedge --reactor filea9.wasm main
[2024-04-12 15:23:41.592] [error] execution failed: out of bounds memory access, Code: 0x408
[2024-04-12 15:23:41.592] [error]     Accessing offset from: 0x100001d29 to: 0x100001d2a , Out of boundary: 0xffffffff
[2024-04-12 15:23:41.592] [error]     In instruction: i32.load16_u (0x2f) , Bytecode offset: 0x000399b4
[2024-04-12 15:23:41.592] [error]     When executing function name: "main"

AOT:

$ ./wasmedgec filea9.wasm filea9_aot.wasm
[2024-04-12 15:23:17.468] [info] compile start
[2024-04-12 15:23:17.501] [info] verify start
[2024-04-12 15:23:17.531] [info] optimize start
[2024-04-12 15:23:18.519] [info] optimize done
[2024-04-12 15:23:18.519] [info] codegen start
[2024-04-12 15:23:19.466] [info] output start
[2024-04-12 15:23:19.473] [info] codegen done
[2024-04-12 15:23:19.483] [info] output start
[2024-04-12 15:23:19.484] [info] output done

$ ./wasmedge --reactor filea9_aot.wasm main
[2024-04-12 15:18:35.804] [error] execution failed: out of bounds memory access, Code: 0x408
[2024-04-12 15:18:35.804] [error]     When executing function name: "main"

q82419 avatar Apr 12 '24 07:04 q82419