Public: anyone can read this; the crew can change it.

One table test pins every renderer's byte cap and its hostile-input answer #15732

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

This adds test/render-hostile.test.ts, one table for every renderer's byte cap and its answer to a hostile file. Running it found six renderers that stalled on hostile files under their caps, from 0.5 s to 11 s of CPU; each is fixed in its own module.

Notes

shipped production is serving it deploy 3fede26

opened this

This adds test/render-hostile.test.ts, one table for every renderer's byte cap and its answer to a hostile file. Running it found six renderers that stalled on hostile files under their caps, from 0.5 s to 11 s of CPU; each is fixed in its own module.

The test has two halves:

  • Caps: for every kind in RENDERERS it checks for a positive entry in RENDER_CAP (a missing one fails by name). For each kind its file name decides, it checks that a file one byte over the cap never reaches the renderer.
  • Bombs: archive, JSON, YAML, XML, CSV and SVG bomb inputs go through rendererFor the way the blob page sends them. Each must come back with its "too large", "too deep" or truncated answer, without throwing, within 250 ms of CPU time (process.cpuUsage, as test/highlight.test.ts does). Each case is rendered once before it is timed, so first-call JIT cost isn't counted. The file joins the gate by itself, since the gate is every test file minus an empty EXCLUDED. It checks caps and time only; fuzz-renderers.test.ts keeps checking that nothing throws or lets markup through.

What the test found, and the fix in each module:

  • YAML (config form, openapi, workflow, compose): 50,000 key: value lines took over 10 s, and 400,000 nested brackets 3 s. The vendored parser costs about 25 µs a line and checks keys quadratically. yamlTooLarge in yaml-config.ts now counts the text first: more than 2,500 items, more than 10,000 lines, or nesting past 64 is refused before parsing. Duplicate keys are checked with a Set and reported at their line and column.
  • GPX and KML: a 5 MB file of tags took 0.4–0.9 s. The shared scanner stops at TOKEN_CAP (100,000 tags), and GPX also at READ_POINT_CAP (25,000 points). The page draws what was read, with a line saying the file goes on; KML says "at least N placemarks", and the terminal adds a "Read: first part only" fact. attr() now uses an exec loop instead of matchAll.
  • fcpxml: 60,000 nested clips took 11 s, because every tag scanned the whole stack. Open spine and clip depth is now counted. fcpxml and kdenlive also stop at TOKEN_CAP tags or READ_CLIP_CAP (10,000) clips and answer "too long to read here".
  • CSV: one 10 MB line of five million cells took 0.8 s. detectDelimiter reads only the first 64 KiB of the first record, and fields that aren't kept are only counted, in a tight loop. A quote inside an unkept field is now read as text, as it already was for a kept field; that edge case gave a different table before.

Look at:

  • A test I changed: in test/render-gpx.test.ts the thinning test fed 30,000 points and expected all of them read. It now feeds 24,000, which is still past POINT_CAP (20,000), the thing it tests.
  • What a person sees: a legitimate GPX track over about 11,000 points with elevation and time is now drawn as its first part, with a note, where before the whole track was drawn after about 0.6 s. A YAML file over the counts above opens as source instead of a form.
  • Left alone: a tar.gz bomb still costs about 130 ms, which is zlib inflating up to the existing 128 MB GUNZIP_CAP. I didn't change kinds.ts: RENDER_CAP is already typed over every kind.

Checks run: bun scripts/gate.ts passes, bun x tsc --noEmit is clean and design lint has nothing to fix. scripts/fast.ts named 628 files (about 52 minutes), so I ran the 102 that cover the changed modules: every render, fuzz, blob, config and terminal-workspace suite, the workflow and CSV page tests, and the feature-doc tests. All pass after the GPX test change above.

Try: push a config.yaml of 50,000 kN: v lines to a repository on the preview and open it: the page says at once that the form cannot hold more than 2,500 lines and items. A .gpx of 30,000 <trkpt lat="1" lon="2"/> points draws with the "file goes on" line.

[{"go":"/","look":"Push a .gpx file of 30,000 <trkpt lat=\"1\" lon=\"2\"/> points to a repository, then open it on its blob page","expect":"The route draws at once, with the line \"The file goes on past the 100,000 tags or 25,000 points the page reads\" under the facts"},{"go":"/","look":"Push a config.yaml of 50,000 \"kN: v\" lines and open it","expect":"The page answers in well under a second: Not valid YAML: The form cannot hold more than 2,500 lines and items"}]

🤖 Generated with Claude Code

Closes #15720

2 earlier comments · 2 events
commented

This adds test/render-hostile.test.ts, one table for every renderer's byte cap and its answer to a hostile file. Running it found six renderers that stalled on hostile files under their caps, from 0.5 s to 11 s of CPU; each is fixed in its own module.

The test has two halves:

  • Caps: for every kind in RENDERERS it checks for a positive entry in RENDER_CAP (a missing one fails by name). For each kind its file name decides, it checks that a file one byte over the cap never reaches the renderer.
  • Bombs: archive, JSON, YAML, XML, CSV and SVG bomb inputs go through rendererFor the way the blob page sends them. Each must come back with its "too large", "too deep" or truncated answer, without throwing, within 250 ms of CPU time (process.cpuUsage, as test/highlight.test.ts does). Each case is rendered once before it is timed, so first-call JIT cost isn't counted. The file joins the gate by itself, since the gate is every test file minus an empty EXCLUDED. It checks caps and time only; fuzz-renderers.test.ts keeps checking that nothing throws or lets markup through.

What the test found, and the fix in each module:

  • YAML (config form, openapi, workflow, compose): 50,000 key: value lines took over 10 s, and 400,000 nested brackets 3 s. The vendored parser costs about 25 µs a line and checks keys quadratically. yamlTooLarge in yaml-config.ts now counts the text first: more than 2,500 items, more than 10,000 lines, or nesting past 64 is refused before parsing. Duplicate keys are checked with a Set and reported at their line and column.
  • GPX and KML: a 5 MB file of tags took 0.4–0.9 s. The shared scanner stops at TOKEN_CAP (100,000 tags), and GPX also at READ_POINT_CAP (25,000 points). The page draws what was read, with a line saying the file goes on; KML says "at least N placemarks", and the terminal adds a "Read: first part only" fact. attr() now uses an exec loop instead of matchAll.
  • fcpxml: 60,000 nested clips took 11 s, because every tag scanned the whole stack. Open spine and clip depth is now counted. fcpxml and kdenlive also stop at TOKEN_CAP tags or READ_CLIP_CAP (10,000) clips and answer "too long to read here".
  • CSV: one 10 MB line of five million cells took 0.8 s. detectDelimiter reads only the first 64 KiB of the first record, and fields that aren't kept are only counted, in a tight loop. A quote inside an unkept field is now read as text, as it already was for a kept field; that edge case gave a different table before.

Look at:

  • A test I changed: in test/render-gpx.test.ts the thinning test fed 30,000 points and expected all of them read. It now feeds 24,000, which is still past POINT_CAP (20,000), the thing it tests.
  • What a person sees: a legitimate GPX track over about 11,000 points with elevation and time is now drawn as its first part, with a note, where before the whole track was drawn after about 0.6 s. A YAML file over the counts above opens as source instead of a form.
  • Left alone: a tar.gz bomb still costs about 130 ms, which is zlib inflating up to the existing 128 MB GUNZIP_CAP. I didn't change kinds.ts: RENDER_CAP is already typed over every kind.

Checks run: bun scripts/gate.ts passes, bun x tsc --noEmit is clean and design lint has nothing to fix. scripts/fast.ts named 628 files (about 52 minutes), so I ran the 102 that cover the changed modules: every render, fuzz, blob, config and terminal-workspace suite, the workflow and CSV page tests, and the feature-doc tests. All pass after the GPX test change above.

Try: push a config.yaml of 50,000 kN: v lines to a repository on the preview and open it: the page says at once that the form cannot hold more than 2,500 lines and items. A .gpx of 30,000 <trkpt lat="1" lon="2"/> points draws with the "file goes on" line.

[{"go":"/","look":"Push a .gpx file of 30,000 <trkpt lat=\"1\" lon=\"2\"/> points to a repository, then open it on its blob page","expect":"The route draws at once, with the line \"The file goes on past the 100,000 tags or 25,000 points the page reads\" under the facts"},{"go":"/","look":"Push a config.yaml of 50,000 \"kN: v\" lines and open it","expect":"The page answers in well under a second: Not valid YAML: The form cannot hold more than 2,500 lines and items"}]

🤖 Generated with Claude Code

Changes requested — before the latest push

The renderer hardening is sound and the table test is a good idea, but three things need fixing in one round.

  1. Flake risk (fix first). test/render-hostile.test.ts holds a 250 ms budget on process-wide CPU (user+system, GC threads included). The pull itself says the tar.gz bomb costs about 130 ms, and the cases build 5-50 MB bodies in the same process. The gate runs on a loaded box, and the direction is 'fast tests that never flake'. Either budget the time per case with real headroom (the bomb itself is the one at risk), or assert the caps structurally (the cut flag, the TOO_LONG answer, the CSV column count) and keep only a generous wall guard such as 2 s. Also move the 16 MiB-times-N gzip construction out of the timed path or shrink it.
  2. Scope. One pull is doing three jobs: the test, a behaviour change for people, and a CSV parser rewrite. Real files are now refused: a GPX over about 11,000 points with ele and time is drawn as its first part, and a YAML config over 2,500 items is no longer a form. It counts brackets inside quoted scalars and block scalars, so a legitimate long flow list is refused. Please say in the docs what a person loses and raise the YAML item cap toward the form's MAX_FIELDS, or count real structure only. Split the CSV fast-path into its own pull if you can. The CSV hot loop also allocates an array per quote ([delim,10,13].includes); compare three charCodes instead.
  3. Both doors. GPX got the 'Read: first part only' fact in the terminal, but KML's cut note has no terminal counterpart: src/tui/screens/kml.ts still shows 'N placemarks' as if complete, while the page says 'at least N'. Add the same note there with a test, and update kml.md's Terminal bullet.

SVG box: the test only asserts an imgview answer, which is not a bomb check on any renderer. Say so in the test, or remove SVG from the claim.

No README addition, design-system markup is right (muted small p, no new classes), and the gate list needs no edit.

commented

One table test now covers every renderer: each kind RENDERERS draws has a byte cap in RENDER_CAP, and a file one byte over it gets Download, not a render. Each hostile file (gzip bomb, deep nesting, a 5 MB single line, entity expansion) must come back with its "too large", "too deep" or cut answer, without throwing. This round follows the review.

  • Flake risk: test/render-hostile.test.ts no longer measures process CPU. Each case checks its answer and, where the renderer exposes it, checks the cap as data: GPX and KML cut, the exact Showing 200 of 500,000 columns, TOO_LONG, and the YAML item and line caps. Time is only a guard of 2 s wall clock per case, measured on one render. Bodies are built before the clock starts. The gzip bomb is now made of 1 MiB members (1 KiB packed each), not a 16 MiB gzip. The 168 cases run in about 3 s.
  • YAML: yamlTooLarge now skips text inside quotes ("…", '…'), block scalars (|, >) and comments. It counts brackets and commas only inside a flow collection, so a long list written inside a string costs nothing. The item cap is now 6,000, three times MAX_FIELDS; it is a literal because of a circular import, and a test pins the relation. The line cap is now 20,000. A test checks that a file the form can hold (2,000 values as a list of maps) is never refused.
  • What a person loses: the docs now say it. In gpx.md, a track past about 11,000 points with ele and time is read as its first part only. In kml.md, placemarks past the 100,000-tag scan are neither listed nor counted. In config-form.md, a YAML file past the caps keeps its source view, and the page says which cap it met.
  • Both doors: in the terminal, a KML file the scan stopped reading now opens on a "(file goes on) · first part only: at least N placemarks" row. The row is first so it is on screen, and the status line's count stays the total read. There is a unit test in test/render-kml.test.ts and a terminal test in test/tui-workspace-formats.test.ts. The terminal bullet in kml.md is updated.
  • SVG: the test now says these two cases only confirm the page hands SVG to the browser in an <img> rather than parsing it. They are not a bomb check on any renderer.
  • Scope: the CSV fast path is out of this pull. csv-parse.ts, its test and csv-view.md are back to main's text, and the CSV cases here use a 1 MB line. On main's parser that takes about 75 ms; a 10 MB line takes 0.5–0.66 s. The fast path, using three char-code comparisons instead of an array per quote, and the 10 MB case are written up as #15739.

scripts/fast.ts found the diff too broad to name tests, so I picked 20 files: the hostile, config/YAML/TOML, KML, GPX, CSV, timeline, compose, workflow, fuzz-renderer and terminal-formats suites. All 497 tests pass, and tsc --noEmit, design-lint and gate.ts --fix are clean. The gate still notes that detectDelimiter looks like sniffDelimiter in src/text/csv.ts; that file now matches main, so the note isn't from this pull.

To try it: run bun test test/render-hostile.test.ts test/config-yaml-toml.test.ts test/render-kml.test.ts. In the terminal workspace, open a .kml with more than 100,000 tags to see the cut row.

🤖 Generated with Claude Code

Approved

Earlier asks are met: the wall-clock guard replaces the CPU-time flake risk, the YAML cap now skips quoted text, block scalars and comments, what a person loses is documented in gpx.md, kml.md and config-form.md, the terminal says when a KML or GPX file was cut, and the CSV fast path moved out to #15739. Read on the head. Next, two things. (1) Bring the per-case guard down toward the 250 ms the issue asked for, once the box is quiet enough. (2) Land #15739 so the 10 MB CSV line is covered by this table. Non-blocking: the SVG cases only pin the media route; say so in the issue box when it is closed.

commented

Left #15720 open: 2 unticked items remain (For archive, JSON, XML, CSV and SVG kinds it feeds a bomb-shaped input and asserts the render returns within 250 ms with the 'too large' or truncated answer, not an exception.; Anything the test finds is fixed in the same pull, in the module concerned; the test file joins the gate list.).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs