Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two cases of quadratic behavior (GHSA-66g8-4hjf-77xh) #520

Merged
merged 3 commits into from
Jan 15, 2024

Conversation

nwellnhof
Copy link
Contributor

Fixes the two issues reported here: GHSA-66g8-4hjf-77xh

Also known as CVE-2023-24824.

If we find consecutive blank lines inside a list item, abort early in
check_open_blocks by returning NULL. This makes S_process_line skip the
calls to open_new_blocks and add_text_to_container. open_new_blocks is a
no-op for blank lines. add_text_to_container would add an empty line
only for code and HTML blocks which we account for in check_open_blocks.

Fixes part of GHSA-66g8-4hjf-77xh. Obsoletes commonmark#475.
Don't use public tree manipulation API. The cycle detection can result
in quadratic behavior in deeply nested trees. Manipulate the tree
structure manually which is error-prone but also more efficient.

Fixes part of GHSA-66g8-4hjf-77xh.
@jgm jgm merged commit 76cbc2d into commonmark:master Jan 15, 2024
11 of 12 checks passed
@jgm
Copy link
Member

jgm commented Jan 15, 2024

This gave me a pretty significant speedup on our regular make bench - from 0.052 to 0.042 s.

@nwellnhof
Copy link
Contributor Author

The speedup is probably caused by the change to S_insert_emph.

@jgm
Copy link
Member

jgm commented Jan 15, 2024

Yes - saw that!

@nwellnhof nwellnhof deleted the quadratic-behavior branch March 25, 2024 16:58
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.

2 participants