Skip to content

Report repeated <html> and <body> cost to html5ever, and track its attribute-name fix #599

Open

Description

@JuroOravec

html5ever is a Rust HTML parser. A tokenizer splits HTML text into tags and text, and a tree builder arranges those into elements. Citry uses html5gum as the tokenizer and html5ever as the tree builder, with markup5ever_rcdom (a plain in-memory tree from the html5ever repository) holding the result, to build the tree its output checks read. Citry pins html5ever 0.29.0 and rcdom 0.5.0-unofficial. Two kinds of input make their time grow with the square of the input size. This issue tracks getting both fixed upstream, then revisiting Citry's own limits.

What happens in html5ever

  1. One tag with many attributes. The tokenizer's finish_attribute compares each new attribute name with every name already read for the tag, so a tag with n attributes costs about n squared comparisons. This is already reported upstream as servo/html5ever#796, with a fix proposed in servo/html5ever#804. Since 0.7.0 Citry reads every page with html5gum feeding html5ever's tree builder, so html5ever's own tokenizer is not on Citry's path. So this item does not affect Citry. We track it because other users of html5ever are affected.
  2. Repeated <html> and <body> tags. When a page repeats one of these start tags, HTML tells the parser to copy the new tag's missing attributes onto the first element. For each repeated start tag, rcdom's add_attrs_if_missing builds a set of every attribute that the page's first <html> or <body> element has collected so far. When each repeated tag brings new names, that first element keeps growing, and every later tag pays for all of them again. We found no upstream report for this one.

Both are slow inputs, not crashes. Citry limits its input before the tree is built; other programs that parse untrusted HTML may want the same.

What users see in Citry

Citry 0.7.0 refuses a tag with more than 1,024 attributes and a page with more than 16 start tags of any one of html, head and body, before the tree is built (html_limits.rs; the security page lists the limits). A strict output check raises ValueError for such a page, a warn-mode check warns, and Markup or <c-raw> HTML over a limit in an interactive component raises ValueError. The limits are part of GHSA-vgc3-4q38-q7vf.

What we want

  1. Report item 2 to html5ever through the channel the maintainer chooses, with a small Rust program that prints its own timings. Before filing, measure on the newest html5ever release: Citry has measured only 0.29.0. Suggested fix: check each new attribute against the existing ones without rebuilding a set on every call.
  2. Watch servo/html5ever#796 and #804 for item 1.
  3. When a release fixes item 2, move Citry's pins to it and measure again. Then decide whether the limit of 16 start tags can be raised or removed. Keep a limit that still bounds another cost, such as the 1,024-attribute limit.

If upstream declines

Citry keeps its limits, and this issue closes with the reason.

Done when

  • Item 2 is reported to html5ever, and this issue links the report.
  • A fixed html5ever or rcdom is pinned, or upstream has said it will not change.
  • The 1,024-attribute limit and the 16-start-tag limit are raised, removed, or kept on purpose, and the security page says which.

Activity

  1. JuroOravec commented on Nov 2, 2026

    @JuroOravec
    MemberAuthor

    Reported upstream as servo/html5ever#812 (repeated <body> tags, misnested formatting tags, deep nesting, and text inside many tables, measured on html5ever 0.39.0).

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions