Repository navigation
Conversation
fd09099 to
6652148
Compare
|
@alan-agius4 , Sorry to bother you , I think this is ready to merge |
|
Thanks for putting this together — the fix is clean, well-scoped, and performs well (0% overhead on normal HTML and actually ~4.5× faster with ~45% less memory than Just one security issue to address before merging, plus a small perf/architecture suggestion and a few minor nits: 1. Escape unterminated
|
Serialize adjacent Text and CDATA children of fallback raw-content elements as one run, so closing tags and comment delimiters split across nodes are escaped where the parser sees them. A run of Text and CDATA nodes is the largest span that can reconstruct these tokens, because every other serialized node starts with `<`. Escape an unterminated `<!--` in fallback raw text as well. It would keep the comment open past the closing tag of the element until a later `-->`, such as one in the JSON of the TransferState script, and turn that raw text into live HTML.
6652148 to
b4622d1
Compare
|
Thanks for the review. Everything is addressed in b4622d1, which is rebased on 1. Unterminated
The 2. Perf /
Instructions per serialization, measured with
3. Nits. All done:
One observation: with (1) in place, escaping one node at a time is already safe. A fuzz over 200k random fallback trees found no closing tag of the element or its ancestors and no comment left open. What coalescing adds is that a comment split across nodes stays a comment, and it is faster. |
Serialize adjacent Text and CDATA children of fallback raw-content elements (
<noscript>,<iframe>,<noembed>,<noframes>) as one run. Closing tags and comment delimiters split across nodes are then escaped where the parser sees them. A run of Text and CDATA nodes is the largest span that can rebuild these tokens, because every other serialized node starts with<.Escape an unterminated
<!--in fallback raw text too. Otherwise the comment stays open past the element's closing tag until a later-->, such as one in the JSON of the TransferState<script>, and that raw text becomes live HTML. This includes a comment opener split across text nodes, such as['<!', '--'].How it works:
serializeChildren()passes Text and CDATA nodes to an outlinedserializeText()helper.serializeOne()used to make. It coalesces only inside fallback raw-content elements, andserializeChildren()carries on after the run.serializeOne()still serializes one node.<!--.test/html5lib-tests.jsonupdates only the 16 cases with an unterminated<!--in fallback raw text. Runningupdate-html5lib-tests.json the whole file would also rewrite 15 unrelated entries that are already stale onmain.Instructions per serialization, measured with
perf stat. An A/A copy ofmainstays within ±0.8%.main<noscript><noscript>with a 5,000-node@forrunFixes angular/angular#70462