ctor-eval crashes when a non-env imported memory is written to

Open
#8,146 0 comments 0 reactions 1 assignee View on GitHub

@stevenfontanella is already working on this.

Since Dec 18, 2025.

Assessment

This issue has not been assessed yet.

Description

Similar to #8145, ctor-eval crashes when the ctor writes to an imported memory. We should throw FailToEvalException and stop evaluation instead of crashing.

Repro:

(module
 (import "import" "memory" (memory $memory 1 1))
 (func $foo (result i32)
  (i32.store (i32.const 1) (i32.const 1))
  (i32.const 1)
 )
 (export "foo" (func $foo))
) 
ninja && python3 check.py ctor-eval --filter='*imports*'
ninja: no work to do.

[ checking wasm-ctor-eval... ]

.. imports.wast
executing:  /usr/local/google/home/stevenfont/code/binaryen/bin/wasm-ctor-eval /usr/local/google/home/stevenfont/code/binaryen/test/ctor-eval/imports.wast -all -o a.wat -S --ctors foo
terminate called after throwing an instance of 'std::out_of_range'
  what():  map::at
^C
Traceback (most recent call last):
  File "/usr/local/google/home/stevenfont/code/binaryen/check.py", line 436, in <module>
    sys.exit(main())
             ~~~~^^
  File "/usr/local/google/home/stevenfont/code/binaryen/check.py", line 419, in main
    TEST_SUITES[test]()
    ~~~~~~~~~~~~~~~~~^^
  File "/usr/local/google/home/stevenfont/code/binaryen/check.py", line 121, in run_ctor_eval_tests
    support.run_command(cmd)
    ~~~~~~~~~~~~~~~~~~~^^^^^
  File "/usr/local/google/home/stevenfont/code/binaryen/scripts/test/support.py", line 224, in run_command
    out, err, code = _subprocess_run(cmd, stdout=subprocess.PIPE, stderr=stderr, encoding='UTF-8')
                     ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/stevenfont/code/binaryen/scripts/test/support.py", line 201, in _subprocess_run
    proc = subprocess.run(*args, **kwargs)
  File "/usr/lib/python3.13/subprocess.py", line 556, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
                     ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/subprocess.py", line 1209, in communicate
    stdout = self.stdout.read()
KeyboardInterrupt
Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 20h
Merged PRs (30d)
64

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from WebAssembly/binaryen

All issues in WebAssembly/binaryen

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.