Skip to content

A page with ~640K+ class tokens (1.2 MB attribute) overflows the linkedom parse and fails the whole audit #1557

Closed

Description

@nc9

What happens

One page whose class attribute holds more than about 638 K class tokens makes the HTML parse throw RangeError: Maximum call stack size exceeded. The throw isn't contained to that page: the whole audit fails and no report is written, so every other page's results are lost too.

The overflow is in linkedom 0.18.13. Its className setter spreads every token into one call, classList.add(...(String(value).split(/\s+/))) (esm/interface/element.js), reached from htmlparser2 during parseHTML. That means the limit is a count of tokens, not bytes. The tokens don't have to be distinct, so a 1.22 MB attribute is enough, far under the crawler's 10 MB page cap.

Evidence

Measured offline on Boat, with fixtures built at runtime and nothing external fetched.

  • Parser alone (linkedom.parseHTML, parser.parseDocument, parseHtmlForRules):
    • one-letter classes parse at 637,890 tokens and throw at 638,769 tokens (a 1.22 MB attribute);
    • longer names (c0 c1 …) parse at 500 K tokens (3.7 MB) and throw at 750 K (5.6 MB);
    • the same 1.28 M tokens in a data-x attribute parse fine.
  • Versions: v0.0.157 and v0.0.159 are identical, so this predates both.
  • Real CLI audit (v0.0.159, squirrel audit http://127.0.0.1:<port>/ --offline --passive --no-publish): a local three-page fixture site of normal home and B pages plus one page with a 7.5 MB class attribute. The audit exits 1 with ✗ Audit failed: Maximum call stack size exceeded. and writes no report.
  • Not measured: the hosted worker. It uses the same engine parse, so the hosted audit most likely fails the same way. Check it.

Before changing anything

Check where a parse failure should be contained, the crawl-time parse and the rules parse alike. Find out whether another linkedom path (setAttribute("class"), classList.value) spreads tokens in the same way. Also decide whether to patch around it (cap or normalize the class token count before the setter sees it) or to contain any parse throw per page.

Acceptance Criteria

  • On a site where one page's parse throws, the audit completes and writes a report. Every other page is audited normally, and the failing page is listed with a visible parse-failure notice instead of silently vanishing. This holds for the CLI and the hosted worker.
  • A page with a class attribute of 1 M or more tokens, distinct or repeated, no longer throws. The rest of the page (later elements, images, scripts) still reaches the rules, checked with a marker placed after the big element.
  • A test builds the fixture at runtime (no multi-MB fixture file in the repo) and fails if the RangeError or the whole-audit failure comes back.
  • The PR states whether the fix is a workaround in our parser wrapper or an upstream linkedom change, and links any upstream report.

Activity

  1. added
    bug
    size: M
    rules
    on Nov 2, 2026
  2. added theissue type on Nov 2, 2026
  3. nc9 commented on Nov 4, 2026

    @nc9
    ContributorAuthor

    Acceptance check against v0.0.162 (7c31d5b). The fix shipped in v0.0.161: b7ea286, b576fa9, 50b3a74 (stacked from agent branches, no per-issue PR).

    # Criterion Result Evidence
    1 One page's parse throwing: the audit completes and writes a report, the other pages are audited, the failing page carries a visible notice; CLI and hosted worker PASS Every parse goes through the contained parseHTML in packages/parser/src/dom.ts (it is the only value import of linkedom in the repo; the rest are type imports), so the CLI, the engine and the hosted worker share it. packages/audit-engine/tests/huge-class-parse-1557.test.ts runs runStreamingRules over a 1,000,000-token page and a normal page: both audited, crawl/html-size has an html-parse warn on the big page only. I also ran the CLI from the v0.0.162 tree against a local three-page site with one 700,000-token class page (audit --offline --passive --no-publish --http -f json): exit 0, a report written, all 3 pages audited, html-parse warn on the big page. The hosted worker itself was not run here.
    2 A class of 1 M or more tokens no longer throws and later elements still reach the rules (marker after the big element) PASS huge-class-1557.test.ts "1 million repeated tokens parse: the elements after it reach the document, with a notice" and "distinct tokens: the first 20,000 are kept, in order" (700,000); the engine test finds the image without alt placed after the big element.
    3 A runtime-built fixture that fails if the RangeError or whole-audit failure returns PASS Fixtures are built from Array.from in the tests; no multi-MB file in the repo; "which failures parseHTML retries" in parse-contained-1557.test.ts covers the retry and empty-document paths.
    4 States whether the fix is a workaround in our wrapper or an upstream change, and links any upstream report PASS dom.ts header and the changelog entry state it is contained in our parser wrapper (the one place pages are parsed), with a retry cut and an empty-document fallback. No upstream linkedom report is linked, and none is referenced in the repo.

    Ran: huge-class-1557.test.ts (12 pass), parse-contained-1557.test.ts (6), huge-class-parse-1557.test.ts (1), html-size-parse-notice-1557.test.ts (3).

    Ticked 1 to 4 and closing. Follow-up work that was split out of this fix stays on its own issues (a CLI end-to-end test and the empty-document findings are on #1570; the differential test is on #1569).

    nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrulessize: M

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions