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

Generated binary crashes with "RuntimeError: memory access out of bounds" #3910

Open
womeier opened this issue Apr 1, 2024 · 0 comments
Open
Labels

Comments

@womeier
Copy link

womeier commented Apr 1, 2024

Description

The wasm-bindgen build command succeeds, but the generated binary crashes with RuntimeError: memory access out of bounds.
main.rs is generated by the https://github.com/AU-COBRA/coq-rust-extraction plugin, it could be a bug there as well. I suspect it's in wasm-bindgen, because the setup works with a standard rust setup.

Working setup without wasm-bindgen

sm_gauss_nat-working.zip

cargo run in the attached project works, it prints the expected result Some(O(PhantomData<&()>)).
(The source program takes an arithmetic expression representing the sum of 1 to n, compiles it to a toy stack-machine
and executes it, then subtracts n*(n+1)/2 from the result, so the expected value is 0.)

Steps to Reproduce

sm_gauss_nat-crashing.zip

In the attached project, the main file is exactly the same as in the working one above,
except for the lines at the bottom related to wasm-bindgen.

  1. wasm-pack build --target nodejs
  2. in pkg/sm_gauss_nat.js: replace write_string with console.log and add wasm.main() at the bottom
  3. then run with nodejs: node --stack-size=1000000 sm_gauss_nat.js
  4. Fails with the following error

Error

wolfgang@laptop:~/sm_gauss_nat-extracted/pkg$ node --stack-size=1000000 sm_gauss_nat.js 
wasm://wasm/0005b416:1

RuntimeError: memory access out of bounds
    at wasm://wasm/0005b416:wasm-function[22]:0x3b74
    at wasm://wasm/0005b416:wasm-function[22]:0x3b3d
    at wasm://wasm/0005b416:wasm-function[22]:0x3b5f
    at wasm://wasm/0005b416:wasm-function[22]:0x3b3d
    at wasm://wasm/0005b416:wasm-function[22]:0x3b5f
    at wasm://wasm/0005b416:wasm-function[22]:0x3b3d
    at wasm://wasm/0005b416:wasm-function[22]:0x3b5f
    at wasm://wasm/0005b416:wasm-function[22]:0x3b3d
    at wasm://wasm/0005b416:wasm-function[22]:0x3b5f
    at wasm://wasm/0005b416:wasm-function[22]:0x3b3d

Node.js v20.11.1

Possibly relevant

The main.rs is generated by a compiler, and the setup with the wasm-bindgen macros works as expected on a few other programs. We have some other Wasm binaries here, which one can run with included Node.js based run script,
I can provide more source code for the working examples in case it helps.

Thanks!

@womeier womeier added the bug label Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant