[wasm2js] Enforce declared memory maximum in __wasm_memory_grow#8352
Open
sumleo wants to merge 2 commits intoWebAssembly:mainfrom
Open
[wasm2js] Enforce declared memory maximum in __wasm_memory_grow#8352sumleo wants to merge 2 commits intoWebAssembly:mainfrom
sumleo wants to merge 2 commits intoWebAssembly:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
__wasm_memory_growJS 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.maxwhen the memory has one, generating an additional(newPages <= max)condition in the grow function's guard clause.grow-memory-max.wast) that exercises memory growth with a declared maximum.Test plan
binaryen-unittests)check.py wasm2js), including the newgrow-memory-max.wasttestemscripten-grow-yestests which declare(memory 256 1024)-- now correctly includes(newPages <= 1024)in the grow guardnewPages < 65536)