Repository navigation
Ariadne loader: the schema check goes 128 levels of YAML deep, and a scene node is a level - #1588
Merged
Merged
Conversation
…most 256 levels The .ari loader parsed a document a level at a time with a 95 KB frame (parse_widget_impl: MSVC gave each by-value Widget temporary of its per-kind branches a slot of its own), so a load took about 100 KB of stack a widget level and 200 KB an include: level: 9 include: levels on wasm's 2 MiB stack, 40 on 8 MiB (the 41-deep `ari snapshot` crash). - parse_widget_impl's branches are never-inlined functions, each building its widget in place. parse_widget, parse_seq, expand_include, expand_load and parse_document build in place too, and what a level does besides going down is in functions of their own. MSVC Release frames: parse_widget_impl 95,656 -> 248 bytes, expand_load 11,384 -> 584, parse_document 6,264 -> 344, parse_seq 3,432 -> 568, expand_include 3,384 -> 296. A level now takes about 0.9 KB through include:s: 1,177 include: levels load on 2 MiB (was 9), 266 on 512 KiB (was 1). - kMaxNesting (256, loader.h): a widget is a level, and so is each include: and load: entry, counted across every unit and fragment (Nesting, shared by a load:'s sub-Ctx). The first widget past it stops the parse and the load fails, its error at the widget's place (in an include: expansion, the same place in the unit's template), counting the include:s and load:s on the way and naming each that goes into another file. LoadResult::error_source, error_line and error_column hold the place. The shipped documents nest at most 11 levels. - ari validate reports such an error at its place (file:line:col: error: ...), and --json adds load_error_source, load_error_line and load_error_column. - any_descendant_repeats and refs_from_widget are loops. Tests: the loader at the limit and one past it through plain children, include: and load:; a document at the limit through include:s and through load:s loads and draws on a 2 MiB stack (8 MiB in a Debug build); ari_validate_too_deep; probes for the schema check and yaml-cpp's parse alone, and for a deep fragment loaded at the limit. docs/ARIADNE.md §6.7, with §6.1, §6.3, §14.3.
…scene node is a level Two recursions in a load were bounded only by yaml-cpp's ~500-level parse cap, not by kMaxNesting. Both now keep a load well inside wasm's 2 MiB stack. The schema check (json-schema-validator, ~2.8 KB of stack a YAML level in MSVC Release) runs only on a tree at most kMaxSchemaDepth (128, loader.h) levels of YAML deep, ten times the deepest shipped document's 13. An iterative walk (deeper_than) looks first. A deeper document, library, fragment or include: expansion is not checked and gets one SchemaIssue at its first value past the limit, saying so. A load goes on, as for any schema issue; ari validate fails the document. Chosen over refusing a fragment by the nesting levels left: that would leave the main document's check at 1.25-1.5 MiB, and YAML depth is not widget depth. parse_scene_node builds in place. Its keys and its repeat: are in never-inlined helpers (scene_node_keys, scene_node_repeat), and expand_use is never inlined. Its frame drops from 8,760 to 568 B (MSVC) and from 2,048 to 176 B (wasm32). A scene node is a level of the Nesting count, and so is a use: of a prototype. Scenes are parsed after the widgets, so a scene has all 256 levels. Through use:s a scene could otherwise nest without end with its YAML a few levels deep. Past the limit the load fails at the node (in a prototype's instance, where the node is written in the prototype), with the use:s on the way counted. load_node's two nesting failures share fail_nesting. Measured, MSVC Release, the least stack each loads on (Windows rounds to 64 KiB): - a scene nested to the limit through use:s: 2,176-2,240 KiB (past 2 MiB) -> 128-192 KiB - a scene written inline as deep as yaml-cpp reads: 2,112-2,176 -> 384-448 KiB - a document as deep as yaml-cpp reads: 1,280-1,344 -> 384-448 KiB - a fragment that deep loaded at level 254: 1,536-1,600 -> 640-704 KiB Tests: ariadne_deep_nesting_test loads each worst case on 1 MiB (half of 2 MiB; 8 MiB in Debug), with new probes for scenes. ariadne_loader_test covers a scene at 256 and 257 levels (placed in the prototype) and a scenes: entry. ariadne_schema_test covers a document at kMaxSchemaDepth (checked) and one level past it (one placed issue, which a load warns). docs/ARIADNE.md 6.7, 14.2 and the prototypes note are updated.
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.
The nesting limit of #1586 (
kMaxNesting, 256) counted widgets,include:andload:entries. Two parts of a load still went down a document a level at a time with nothing counting them, bounded only by yaml-cpp's ~500-level parse cap. This PR bounds both, so every load keeps at least half of wasm's 2 MiB stack.Stacked on #1586: this branch is its head (d0587dc) plus one commit, c2421bc. Review that commit. Once #1586 squash-merges, this gets rebased onto master.
The two recursions, before and after
The least stack each worst case loads on, MSVC 14.44 Release x64, bisected with
ariadne_deep_nesting_test's probes. Windows rounds a thread's stack to 64 KiB, so each is given as fails on / passes on:use:s of prototypes (256 levels)load:ed at level 254The rows at 384 / 448 KiB now cost what yaml-cpp's own parse of that YAML costs (
DISABLED_ProbeParseInlineGroupsat 246 needs the same). The worst case of a load is now the fragment row, about a third of 2 MiB.1. The schema check stops at 128 levels of YAML
check_schema→yaml_to_json+ json-schema-validator takes about 2.8 KB of stack per YAML level, inside the validator, where the loader can't shrink it. So the check now runs only on a tree at mostkMaxSchemaDepthlevels of YAML deep (loader.h, 128; the document orinclude:expansion is level 1).deeper_than) checks the depth first.include:expansion that goes deeper is not checked. It gets oneSchemaIssue, at its first value past the limit:nested more than 128 levels of YAML deep, the most the schema check goes (docs/ARIADNE.md §6.7): this document is not checked.ari validatefails the document (exit 1) and prints the issue at its place (deep70.ari:4:1566: /windows/0/children/0/...: nested more than 128 levels ...).Why this option and not refusing a fragment whose YAML can't fit the nesting levels left:
state:value or scene would be refused though its widgets fit.Why 128:
.aridocuments in the tree (volume_grid.ari). The deepest scene among them is 2 nodes.2.
parse_scene_node: a small frame, and a level of the countIt's split the way #1586 split
parse_widget_impl. It builds in place (SceneNode &). Its keys go inscene_node_keysand itsrepeat:inscene_node_repeat, bothCVC_ARI_NOINLINE, andexpand_useis no longer inlined into it. Frames in bytes (MSVC from the/FAslisting, alloc + pushes; wasm32 fromem++ -O2prologues,loader.cppalone):parse_scene_node(on the way down)scene_node_keys(never on the way down)scene_node_repeat(after the children)expand_use(returns before the recursion)load_node(once per load)Decision: scene depth counts toward the
Nestinglimit; it gets no cap of its own.use:. The prototype's node goes a level below itsuse:, as a unit's widget goes below itsinclude:entry.use:s of prototypes thatuse:others, a scene nests without end while its YAML stays a few levels deep. On Ariadne loader: about 1 KB of stack a level, and a document nests at most 256 levels #1586, 128 chained prototypes (256 levels) needed 2.2 MiB.place_ofnow mapsuse:expansions as it mapsinclude:s):Scene depth per stack (MSVC Release)
use:s, #1586load_node's two nesting failures now sharefail_nesting, so its frame stays near #1586's.Tests
ariadne_deep_nesting_testloads each worst case on 1 MiB, half of wasm's 2 MiB (8 MiB in a Debug build): the fragment at level 254, the document and the inline scene at yaml-cpp's cap, and the scene at the limit. A scene one level past the limit fails there. There are new probes for scenes,DISABLED_ProbeLoadSceneInlineandDISABLED_ProbeLoadScenePrototypes.DISABLED_ProbeValidateInlineGroupsnow expects the not-checked issue past the limit.ariadne_loader_test:NestingLimitCountsSceneNodesAndUses(256 loads; 257 fails, placed at its line and column in the prototype, counting theuse:s) andNestingLimitCountsEveryScene(ascenes:entry).ariadne_schema_test:TheCheckGoesAtMostkMaxSchemaDepthLevels. A document at 128 levels is checked; one a level deeper gets one issue, with its pointer, line, column and message, and a load warns it.Run locally (Windows, MSVC Release, with the validator and FTXUI):
ariadne_deep_nesting_test: 17 passed, 1 skipped (tvision).ariadne_loader_test: 279.ariadne_schema_test: 13 + 1 new, 1 skipped.ariadne_host_test: 69.ariadne_runtime_test: 368.ari_*ctests that are built here.Not run here: Linux, macOS, wasm, Debug (CI). The validator's own frames on wasm weren't measured; only
loader.cppwas compiled for wasm.Docs
docs/ARIADNE.md§6.7 covers scenes in the count, the scene error, a scene level's cost, and the schema check's limit with the numbers above.kMaxSchemaDepth.use:is a level.Conflicts expected
The same as #1586's (#1566
read_fragment, #1585common_keys); this commit touches neither.