Repository navigation
7.19: engine limits as errors (heap RangeError, native and nesting depth) and hostile-page tests - #296
Closed
atiernan wants to merge 8 commits into
Closed
7.19: engine limits as errors (heap RangeError, native and nesting depth) and hostile-page tests#296atiernan wants to merge 8 commits into
atiernan wants to merge 8 commits into
Conversation
…ng and RegExp limits (7.19) The heap counts bytes (cells, string payloads, properties) against a settable limit; an op that runs out throws a RangeError made from a 64 KiB reserve, and OutOfMemory only once that is spent. Nested runs of the interpreter loop count against the native depth too, so recursion through ToPrimitive cannot overflow the host stack; the default drops from 150 to 32, measured at about 40 KB of host stack a level unoptimised. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…esting limit (7.19) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Endless loop (Terminator), unbounded recursion through JS, natives and ToPrimitive, a gigabyte string build, catching the heap limit for ever, growing arrays and objects, 10^6 nested arrays in source and in JSON, and recursion through the embedder's own natives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…7.19) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…oop (7.19) clazel-js is a dev-dependency only, for tests/hostile.rs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ir errors Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ds globals with ToString Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
atiernan
had a problem deploying
to
full-verification
November 23, 2026 14:54 — with
GitHub Actions
Error
This was referenced Nov 23, 2026
Member
Author
|
Contained in #302 (engine: Object, classes, Map/Set, Reflect), which merges this branch; one verification. Branch kept. |
This branch was successfully deployed
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.
Phase 7 item 7.19 (limits and hostile pages) for the JS engine, on top of the integration branch (#286).
Limits
Every limit is a field of
clazel_js::Limits. The engine has noDefault.Limits::recommended()is a new named starting point for untrusted pages on a 2 MiB thread stack, andLimits::unlimited()is unchanged. The values below arerecommended().heap_bytesRangeError("Out of memory: the heap limit was reached") that JS can catch. It is made from a 64 KiB reserve past the limit. Once the reserve is spent too, the run ends inError::OutOfMemory, which JS cannot catch.value_stack_bytesRangeError"Maximum call stack size exceeded" (this already existed)native_depthRangeError. It now applies to every VM native, not only to the embedder's closures. Nested runs of the interpreter loop (ToPrimitive callingtoString) are bounded at the limit plus one.nesting_depthSyntaxError, checked on the height of the parse tree.JSON.parse: aSyntaxError(7.11's listed deviation).JSON.stringify: aRangeError. The fixed caps stay and the smaller value applies: 1024 for source, 512 forJSON.parse, 128 forJSON.stringify.regexp_backtrack_entriesVm::regexp_backtrack_limit) for the RegExp built-in, which does not exist yet. The matcher givesStackOverflow, and the engine will report that as aRangeError.code_bytesclazel-webevent_loop::Limits)Limits::default(), unchanged)LimitError::TooManyTimers. The test binding turns it into aRangeError. HTML specifies aQuotaExceededError, which needs aDOMException.How it works
Heap byte count (
clazel-js-vmheap.rs). The VM heap now counts bytes as an estimate:Runtime::heap_usedreports this count. When an op fails withAbrupt::OutOfMemoryinsideVm::execute(or in a native thatVm::callinvoked), the VM throws aRangeErrorbuilt inside the reserve instead.Native depth (
clazel-js-vm).DEFAULT_NATIVE_DEPTHdrops from 150 to 32. I measured the host stack each level of JS → native → JS uses on aarch64 macOS: about 40 KB in debug and 1.5 KB in release. At 150 levels,function f(){[0].forEach(f)} f()overflowed the 2 MiB test-thread stack and aborted the process (SIGABRT) on the base branch. So did recursion through ToPrimitive, which no native counted.Setters.
Runtime::newnow passes every limit to the VM through new setters:set_heap_limit,set_native_depth_limit,set_nesting_depth_limitandset_regexp_backtrack_limit. The VM also gainsVm::check_terminatedfor natives with long loops of their own.Hostile-page tests
All of these pass natively. Under Miri each stays under 300 s; the slowest is about 150 s.
crates/clazel-js/tests/hostile.rsuses the public API only:while(true){}: theTerminator, set from a watchdog thread, ends it withError::Terminated. Neithercatchnorfinallyruns.forEach,map,f.call, and ToPrimitive. Each is a catchableRangeErrorand none overflows the host stack.RangeError.(a+)+bthrough the API: returnsError::NotImplemented, because there is no RegExp built-in. It neither panics nor runs.s = s + sthirty times): aRangeErrorat a 16 MiB heap.heap_usedstays at or below the limit plus the reserve. Building a real 1 GiB string would need a 1 GiB heap, so the test uses the smaller one.OutOfMemory, so it does not hang.pushfor ever ando['k'+i]for ever: aRangeError.SyntaxError. Withnesting_depth: 64, a 100-deep array is also aSyntaxErrorand a 5-deep one parses.SyntaxError. Withnesting_depth: 16, 10 levels parse and 20 levels are aSyntaxError.JSON.stringifyof a 1000-deep object is aRangeError.crates/clazel-js-regexp/tests/limits.rs:(a+)+bon 100 000as with no step budget: ends asMatchError::Interrupted. The interrupt hook reads a flag that another thread sets.crates/clazel-web/tests/hostile.rs(addsclazel-jsas a dev-dependency only):setTimeoutcalls from script, through a test binding overEventLoop. Exactly 65,536 are accepted and the rest are caughtRangeErrors. All accepted timers fire once and the loop ends empty. This takes about 18 s in debug.Not done
clazel-kernel.MutationObserverexists only in the generated WebIDL model, so there is nothing to test.FinalizationRegistry(onlyclazel-js-heap's collector models one), so there is nothing to test.(a+)+bthrough a realRegExp: the RegExp built-in does not exist.regexp_backtrack_entriesis plumbed to the VM for it.clazel-js-heap's collector yet and frees nothing. TheRangeErrortherefore comes at once, and a page that filled the heap leaves it full, so compiling another script in that runtime givesOutOfMemory.joinon a length-2³²−1 array) do not check theTerminator. I addedVm::check_terminatedbut did not edit the built-ins, which another PR is changing.Deviations and behaviour changes
RangeErrorwhere it wasError::OutOfMemory. I updated the assertion ofthe_heap_limit_stops_a_script_that_allocates_for_everintests/api.rsto expect it, and the test now also checksheap_used.Veccapacity is not counted.OutOfMemorybecomes aRangeErrorin every case, including a string pastMAX_LENGTH.Limitsdocs saidJSON.parsegives aRangeError. I followed phase-7.md 7.11 instead: aSyntaxError. The docs are updated.Limits::recommended()is new. The README discussed defaults, and this is a named choice rather than a default. The browser still picks its own values.native_depthvalues:Limits::unlimited()leavesnative_depthatu32::MAX. On a small stack, a page can then overflow the host stack, and this is documented. The VM's default without an embedder drops from 150 to 32.Limits::nesting_depthfor source counts the parse tree's height: the same measure as the parser'sMAX_DEPTH.Verification
cargo xtask verify --changed origin/claude/phase7-integration:status table and images. The message was "no committed row to carry over for clazel-deflate, clazel-forms, clazel-gif, clazel-image-shape, clazel-jpeg, clazel-png, clazel-svg, clazel-webp". This comes from the base'sdocs/STATUS.mdat e35f03f, not from this change. I did not edit STATUS.md.RESULT: FAILED(notCHANGED CRATES PASSED), for that reason only.CI's full verification has not run.
🤖 Generated with Claude Code