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 quadratic performance issue in list numbering #472

Closed

Conversation

kevinbackhouse
Copy link

@kevinbackhouse kevinbackhouse commented Apr 1, 2023

This is a cherry-pick of one of the commits that we added in cmark-gfm to fix GHSA-r8vr-c48j-fcc5. (Only one of the bugs affects cmark too.)

To reproduce the bug:

python3 -c 'n = 10000; print("1.\n" + " 2.\n"*n)' | time ./src/cmark -t commonmark
python3 -c 'n = 10000; print("1.\n" + " 2.\n"*n)' | time ./src/cmark -t man

Increasing the number 10000 in the above command causes the running time to increase quadratically.

The solution is to keep track of the current item number, rather than recomputing it on every iteration by counting the number of elements in the list.

@kevinbackhouse
Copy link
Author

It turns out that this solution is incorrect (see github#321).
I'm going to implement a new solution and post a new PR when it's ready.

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.

1 participant