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
use-after-free in DisposableStack disposal: GC in a disposer marks freed resources (js_dispose_resources) #1564
js_dispose_resources (quickjs.c:54131) has a use-after-free. When DisposableStack.prototype[Symbol.dispose] runs, it frees each resource's value/method inside its LIFO loop but does not shrink resource_count or clear the freed slots until the loop finishes, while js_disposable_stack_mark (quickjs.c:54329) marks resources[0 .. resource_count). A disposer that triggers a GC therefore makes the marker traverse already-freed resources → reference-count underflow / use-after-free.
Reproduces on master d950d55, -O2 -g (and with -fsanitize=address).
PoC (deterministic)
consts=newDisposableStack();s.adopt({},()=>{gc();});// disposed last (i=0); its disposer runs the GCs.use({[Symbol.dispose](){}});// disposed first (i=1); freed before the adopt disposer runss.dispose();
gc() is only used to make the timing deterministic — any disposer that allocates enough to trigger cycle collection hits the same UAF.
In a release build (asserts off) this is a use-after-free / heap corruption rather than an abort.
Fix
The dispose loop frees res->value/res->method but leaves the slot dangling until the loop ends, so a re-entrant GC mark reads freed values. Clear each slot right after freeing it:
Activity
saghul commentedon Jul 14, 2026
Thanks for the report!
saghul commentedon Jul 14, 2026
Fix in #1566
Fix use-after-free in DisposableStack disposal