Parents: #473, #493 Related: #460, #461, #515, #519
Problem
JSON.stringify implements the specification's active Stack cycle check by linearly scanning every currently active ancestor for every object it serializes. An attacker-controlled non-circular chain of depth n therefore performs O(n²) pointer comparisons before the existing native/logical stack guard. Repeated aliases in sibling branches are legal and cannot be rejected by a global visited set.
Scope
- Land benchmark-first acyclic depth-growth rows, a shallow repeated-sibling control, and a deep real-cycle control with frozen topology/output/checksums and source construction outside the timed invocation.
- Add an invocation-local exact-identity membership index for the active specification stack while retaining its ordered push/pop behavior.
- Keep the shallow common path allocation-free; activate bounded index storage only after a fixed stack threshold.
- Preserve callback-observable
toJSON, replacer, Proxy, getter, alias, error, indentation, and property-order semantics.
No-workaround rules
- No lower depth cap, skipped cycle check, permanent object/header marking, process/realm-global visited state, treating sibling aliases as cycles, input preprocessing, benchmark recognition, or changed callback order.
- Do not touch stacks, queues, jobs, Promise/microtask, or Worker lifecycle code.
Acceptance
- Benchmark source, depths, controls, checksums, jobs, warmup, and timed boundary land before the runtime change.
- Active-cycle membership is O(1) expected time beyond a fixed shallow threshold and total index construction/work is O(n), with bounded invocation-local storage.
- Acyclic chains, real ancestor cycles, repeated sibling aliases,
toJSON/replacer-created cycles, and Proxy identity preserve exact specification behavior. - Shallow stringification performs no new membership allocation; index allocation failure leaves stack/index state coherent and propagates OOM.
- JSON.stringify test262, focused OOM/deep/GC/TSan witnesses, forced execution modes where eligible, and full units pass without regressions.
- Seven-pair exact-parent evidence publishes wall, CPU, peak RSS, instructions/cycles/energy availability, thermal state, and dispersion with no discarded samples; shallow control remains neutral.
Security boundary
Object depth, graph shape, aliasing, Proxy/replacer/toJSON callbacks, and allocation pressure are attacker-controlled. The fix must bound cycle-membership work without weakening the exact active-ancestor rule or turning an allocation failure into stale membership state.