Skip to content

Comments

[wasm2js] Enforce declared memory maximum in __wasm_memory_grow#8352

Open
sumleo wants to merge 2 commits intoWebAssembly:mainfrom
sumleo:fix-wasm2js-memory-max
Open

[wasm2js] Enforce declared memory maximum in __wasm_memory_grow#8352
sumleo wants to merge 2 commits intoWebAssembly:mainfrom
sumleo:fix-wasm2js-memory-max

Conversation

@sumleo
Copy link
Contributor

@sumleo sumleo commented Feb 20, 2026

Summary

  • The __wasm_memory_grow JS function generated by wasm2js only checked against the absolute wasm32 page limit (65536) but did not enforce the module's declared memory maximum. For example, a module with (memory 1 2) (max 2 pages) would allow growing beyond 2 pages in the generated JS output.
  • Added a check against the declared max when the memory has one, generating an additional (newPages <= max) condition in the grow function's guard clause.
  • Added a new test (grow-memory-max.wast) that exercises memory growth with a declared maximum.

Test plan

  • All 309 unit tests pass (binaryen-unittests)
  • All wasm2js tests pass (check.py wasm2js), including the new grow-memory-max.wast test
  • Updated expected output for emscripten-grow-yes tests which declare (memory 256 1024) -- now correctly includes (newPages <= 1024) in the grow guard
  • Verified that modules without a declared max still produce the original output (only newPages < 65536)

sumleo and others added 2 commits February 20, 2026 12:02
The generated __wasm_memory_grow JS function only checked against the
absolute wasm32 page limit (65536) but did not enforce the module's
declared memory maximum. For example, a module with (memory 1 2)
would allow growing beyond 2 pages in the JS output.

Add a check against wasm->memories[0]->max when the memory has a
declared maximum, generating an additional (newPages <= max) condition
in the grow function's guard.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant