Repository navigation
abort on allocation failure in wasip1 cabi_realloc - #1315
Merged
saulecabrera merged 1 commit intoOct 18, 2026
Merged
Conversation
saulecabrera
approved these changes
Oct 18, 2026
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.
Description of the change
cabi_reallocin the wasip1 plugin ABI uses the result ofalloc::allocwithout checking it for null. Address 0 is ordinary linear memory on Wasm, so when the allocation fails the host gets 0 back as a success value. The CLI's compile step and every modulejavy buildemits thenmemory.write/memory.initthe JS source, bytecode or export name at address 0 (the far end of the shadow stack in the default plugin, which starts at 1 MiB), and the realloc branch wouldcopy_nonoverlappingthe old contents through the null pointer. Reproduced against the current plugin with wasmtime's memory cap:The same thing shows up end to end. A
javy buildmodule with 704 KB of bytecode, run with a cap 512 KB above its initial memory, keeps executing with the bytecode copied over the start of memory and dies later inside QuickJS with an unrelated[uninitialized]orout of memoryerror. With this change the run stops at the copy withmemory allocation of 703944 bytes failed.The allocation now goes through
alloc::handle_alloc_error, so the failure prints and aborts (anunreachabletrap). That is what wit-bindgen'scabi_reallocdoes for the wasip2 plugins and what any other failed allocation in the plugin already does. The new CLI integration test instantiates the plugin under a 16 MiBStoreLimitscap and checks that an oversizedcabi_realloctraps with the allocation failure on stderr; it fails on the current plugin, which returns 0.Why am I making this change?
Hosts that run Javy output commonly cap instance memory, and a cap hit while the bytecode or source is being copied in currently turns into a silent write over the start of linear memory rather than a reportable error. Checking inside
cabi_reallockeeps the ABI's contract (a returned pointer is valid fornew_sizebytes) local to the one function that promises it.Checklist
javy-plugin-apiif the QuickJS bytecode has changed.javy-cli,javy-plugin, andjavy-plugin-processingdo not require updating CHANGELOG files.