Repository navigation
Description
Stack: #248 → #276 → #277 → (#278 | #279 → #280 → #281 → #282). Each PR body has a link to review just its own diff.
Found while stress-testing #248. All items reproduce identically with and without #248 (published 0.32.0 wasm, local quickjs-emscripten-core). Several are C-side and I could not build wasm locally, so those fixes are proposals. TS-only items are addressed in the linked PR.
Addressed in #278 (stacked on #277, #276 and #248):
setMemoryLimit/setMaxStackSizesilently wrapNaN,Infinityand values >= 2^32 in the 32-bitsize_t(a wrapped value can make every allocation fail or remove the limit). NowRangeError. The max stack size error message said "memory limit".- Pointer arrays are
Int32Array(see the old TODO): heap addresses >= 2 GiB would read as negative. Unreachable with the current 2 GiB cap, but now unsigned. getWasmMemory().grow()called by users bricks the module (HEAPU8is not refreshed). Documented.
Addressed in #279 (C, stacked on #277): dumpMemoryUsage truncation and the callFunction huge-argc crash (the two bullets below marked fixed in #279).
Addressed in #280 (C + TS, stacked on #279): NULL JSContext from newContext, NULL from jsvalue_to_heap, and the unchecked/oversized malloc in QTS_GetOwnPropertyNames.
Addressed in #281 (C, stacked on #280): bjson decode now accepts object references.
Not addressed (need C/build changes or a design decision):
setMemoryLimitis under-enforced on emscripten builds (a hard backstop is proposed separately in Add maxMemoryBytes: a hard cap on WebAssembly linear memory #283:maxMemoryBytes, a cap on wasm linear memory) (usable_size()is 0, so each allocation is counted at its requested size only: a 64 MB limit let 400 distinct 1 MB strings through).setMemoryLimit(0)makes every allocation fail on bellard variants rather than meaning "disabled".- (fixed in Handle allocation failure in newContext, heapValueHandle, getOwnPropertyNames (part of #275) #280)
newContext()does not check for a NULLJSContext(OOM during creation yields a handle on pointer 0). - (fixed in Allow object references when decoding binary JSON (part of #275) #281)
bjsonencode/decode asymmetry:QTS_bjson_encodeusesJS_WRITE_OBJ_REFERENCEbut decode passes different flags, so shared-reference/cyclic objects encode but decode to an error. - (fixed in Fix truncated dumpMemoryUsage and QTS_Call stack overflow with many args (part of #275) #279)
dumpMemoryUsageoutput is truncated at 1023 bytes (fixed 1024-bytefmemopenbuffer,c/interface.c~418). - (fixed in Fix truncated dumpMemoryUsage and QTS_Call stack overflow with many args (part of #275) #279)
callFunctionwith a huge args array:QTS_CallbuildsJSValueConst argv[argc]on the wasm shadow stack; ~650k+ args traps the module. - C
const char *parameters (QTS_Evalfilename,QTS_NewFunctionname) are generated as cwrap"string", which uses stack alloca: very large filenames crash the module. qts_normalize_modulecallsjs_strdup(ctx, NULL)when the host module normalizer throws.getLengthusesJS_ToUint32, so lengths >= 2^32 / negative wrap and getter exceptions are swallowed.- Guest recursion can overflow the host V8 stack before QuickJS's
maxStackSizecheck;setMaxStackSize(0)removes the limit. newVariant({ wasmMemory: <Memory> })instantiated twice shares one memory, breaking the first instance.- Debug (ASan) variants hard-exit at heap exhaustion and are very slow at scale.
Repro scripts for all of these are available; happy to share or turn any into tests.
Activity