Repository navigation
Refuse deeply nested equations instead of overflowing the stack (#69) - #70
Merged
Merged
Conversation
LaTeX, UnicodeMath, MathML or OMML nested a few hundred levels deep overflowed the stack in the readers (LaTeXReader.Pass2, RewriteTeXOnly, the UnicodeMath translator) or the writers, which ends the process. - The XML of a MathML or OMML source, and every equation read, are refused beyond EquationStylesheets.MaxDepth levels (FormatException). - The recursive methods of the readers, the writers and the templates the XSLT generator compiles call RuntimeHelpers.EnsureSufficientExecutionStack: reading turns it into a FormatException (InvalidDataException for MTEF), writing throws InsufficientExecutionStackException, as the OMML stylesheet guard now does too (it threw ArgumentException). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SyVioATwYG9TEkfaF3Xtix
…scripts (#69) A LaTeX equation that the grammar refuses (a chain of \sqrt too long for the stack, for one) said "Not valid UnicodeMath" with the UnicodeMath it was rewritten to: it now says "Not valid LaTeX" with the LaTeX given. Chains without braces (x^x^x..., x_x_x..., x\sqrt\sqrt...) are refused with a FormatException, as nesting is. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SyVioATwYG9TEkfaF3Xtix
The depth check that every equation read now goes through allocated a stack and an enumerator of each element's children, and Parse(MathML) allocated 15-19% more than before. It now walks the tree by its links, and asks HasElements before FirstNode, which would make an XText of the text of every token. The benchmarks against main: the same allocations, or fewer (the OMML stylesheets use the same check), and times within the noise (geometric mean -1.0%). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SyVioATwYG9TEkfaF3Xtix
RejectsDeepOmml(m:nary, 250) failed on net481: 250 n-ary operators are about 502 levels of XML, within MaxDepth, and whether the stylesheet ran out of the 1 MB stack depended on the frames of the runtime (on .NET Framework it did not, and the equation was read). The tests that expect a refusal now nest beyond MaxDepth, or far beyond what any 1 MB stack holds; the equations of the issue, near the limit, are checked to be read or refused, never to end the process. The LaTeX nested 20000 deep (over a minute on net481) is 5000. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01SyVioATwYG9TEkfaF3Xtix
|
|
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.
LaTeX, UnicodeMath, MathML or OMML nested a few hundred levels deep overflowed
the stack in the readers (LaTeXReader.Pass2, RewriteTeXOnly, the UnicodeMath
translator) or the writers, which ends the process.
beyond EquationStylesheets.MaxDepth levels (FormatException).
generator compiles call RuntimeHelpers.EnsureSufficientExecutionStack: reading
turns it into a FormatException (InvalidDataException for MTEF), writing
throws InsufficientExecutionStackException, as the OMML stylesheet guard now
does too (it threw ArgumentException).
Co-Authored-By: Claude Opus 5.5 [email protected]
Claude-Session: https://claude.ai/code/session_01SyVioATwYG9TEkfaF3Xtix