Skip to content

Parse element content iteratively - #155

Merged
adamreichold merged 1 commit into
RazrFalcon:masterfrom
jaytaph:depth-limit
Sep 22, 2026
Merged

adamreichold merged 1 commit into
RazrFalcon:masterfrom
jaytaph:depth-limit

Conversation

@jaytaph

@jaytaph jaytaph commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Document::parse recursed once per level of element nesting without bounds and can result in a stack overflow (which will abort the application).

This commit changes this into a single loop so very deep nestings can be done safely without overflow, and it adds a limit configuration option which can be used to cap the depth.

Fixes #154

Comment thread src/parse.rs Outdated
@jaytaph

jaytaph commented Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

Added additional commit. Can rebase it at a final stage when approved.

Comment thread src/tokenizer.rs Outdated
@jaytaph jaytaph changed the title Parse element content iteratively and add ParsingOption::depth_limit Parse element content iteratively Sep 21, 2026
Document::parse recursed once per level of element nesting without
bounds and can result in a stack overflow (which will abort the
application).

This commit changes this into a single loop so very deep nestings can be
done safely without overflow.

@adamreichold adamreichold left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. (I am holding off merging for a bit to give others a chance to chime in.)

@RazrFalcon

Copy link
Copy Markdown
Owner

Looks good. Except I wonder how long deeply_nested_elements takes to execute. According to GH Actions not as long, so I guess it's fine.

@adamreichold

Copy link
Copy Markdown
Collaborator

Except I wonder how long deeply_nested_elements takes to execute. According to GH Actions not as long, so I guess it's fine.

Takes less than 200ms on my puny Ryzen 5 5600U...

@adamreichold
adamreichold merged commit 3f5c78d into RazrFalcon:master Sep 22, 2026
2 checks passed
@jaytaph
jaytaph deleted the depth-limit branch September 24, 2026 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stack overflow parsing deeply nested elements

3 participants