You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wasm: heap overlaps string literals — programs allocating >1 KiB corrupt their own literals #830
architectureStructural/system-level shape and runtime behaviourbugSomething is broken or behaves incorrectlypriority:p1High - schedule nextscope:repoConfined to this repository
Core-wasm memory corruption on main (ee211d3). The heap-pointer global started at a fixed address, 1024. String literals were laid out from a fixed address, 2048. Any program that bump-allocates more than about 1 KiB overwrites its own literals.
Sixty println("label_number_N" ++ " ok"); calls in main, compiled with affinescript compile repro.affine -o repro.wasm and run with bun run repro.wasm:
label_number_1 ok
…
label_number_21 ok
label_number_22abe
RuntimeError: Out of bounds memory access
The interpreter (affinescript eval) prints all 60 lines.
This is silent corruption, not a loud failure: line 22 is a plausible-wrong value printed before anything traps. A program that allocates less, or writes over a literal it never prints, corrupts data without trapping.
Scope
Affected: the core-wasm backend (lib/codegen.ml), including the Node-CJS / --vscode-extension wrapper, which embeds the same module.
Not affected: WasmGC, Bun-ESM, plain JS, the interpreter, and the TEA bridge modules (they have no data segments).
There is no memory.grow path. Exhausting the single page traps loudly.
The pinned commit (ee211d3), the 60-println repro and the side-by-side with affinescript eval make this straightforward to verify.
On the core-wasm backend (lib/codegen.ml), the heap pointer starts at address 1024 and string literals are laid out from 2048. Any program that bump-allocates more than about 1 KiB writes over its own literals. The failure is usually silent: line 22 prints a wrong but plausible value before anything traps. The Node-CJS / --vscode-extension wrapper is affected too, because it embeds the same module. WasmGC, Bun-ESM, JS, the interpreter and the TEA bridge are not affected.
Nothing is missing for a fixer. A regression test that allocates past the old 1 KiB boundary and checks literal integrity would keep the fix from being undone.
flowchart LR
A[📊 Heap starts at 1024] --> B[🔄 Bump alloc grows upward]
B --> C[⚠️ Passes 2048 after about 1 KiB]
D[💾 String literals at 2048] --> C
C --> E[🔴 Literals silently overwritten]
architectureStructural/system-level shape and runtime behaviourbugSomething is broken or behaves incorrectlypriority:p1High - schedule nextscope:repoConfined to this repository
Activity
whatproblem-ai commentedon Dec 1, 2026
The pinned commit (
ee211d3), the 60-printlnrepro and the side-by-side withaffinescript evalmake this straightforward to verify.On the core-wasm backend (
lib/codegen.ml), the heap pointer starts at address 1024 and string literals are laid out from 2048. Any program that bump-allocates more than about 1 KiB writes over its own literals. The failure is usually silent: line 22 prints a wrong but plausible value before anything traps. The Node-CJS /--vscode-extensionwrapper is affected too, because it embeds the same module. WasmGC, Bun-ESM, JS, the interpreter and the TEA bridge are not affected.Nothing is missing for a fixer. A regression test that allocates past the old 1 KiB boundary and checks literal integrity would keep the fix from being undone.
flowchart LR A[📊 Heap starts at 1024] --> B[🔄 Bump alloc grows upward] B --> C[⚠️ Passes 2048 after about 1 KiB] D[💾 String literals at 2048] --> C C --> E[🔴 Literals silently overwritten]🏆 Clarity Score: 95% - Very well written! ✨
⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy
fix(codegen): start the wasm heap after the last data segment (#830)
fix(codegen): start the wasm heap after the last data segment (#830)