Protect against quadratic generated table size explosion#146
Merged
jgm merged 1 commit intojgm:masterfrom Feb 3, 2024
Merged
Conversation
This commit adds a limit to the number of auto-completed cells
around 200,000. The result is, in these original samples:
python -c 'N=100; print("x|" * N + "\n" + "-|" * N + "\n" + "x|\n" * N)' | commonmark --extension=pipe_tables | wc -c
102362
This is unchanged.
$ python -c 'N=1000; print("x|" * N + "\n" + "-|" * N + "\n" + "x|\n" * N)' | commonmark --extension=pipe_tables | wc -c
2025878
This, however, is much lower. The parser is refusing to parse the row where the limit is hit,
and switches to parsing it as text instead.
$ python -c 'N=10000; print("x|" * N + "\n" + "-|" * N + "\n" + "x|\n" * N)' | commonmark --extension=pipe_tables | wc -c
2240258
It's not quadratic any more (without this commit, it was 1000230062).
At the limit, 200,000 autocompleted rows is approximately "</td><td>".len * 200,000
generated data, or 1.8Mbyte of data. The above examples show about 2Mbytes,
thanks to the row tags and text overhead, and when the parser breaks out of the table
it's still including the remaining "rows" as text.
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.
Fixes #145
This commit adds a limit to the number of auto-completed cells around 200,000. The result is, in these original samples:
This is unchanged.
This, however, is much lower. The parser is refusing to parse the row where the limit is hit, and switches to parsing it as text instead.
It's not quadratic any more (without this commit, it was 1000230062).
At the limit, 200,000 autocompleted rows is approximately
"</td><td>".len * 200000generated data, or 1.8Mbyte of data. The above examples show about 2Mbytes, thanks to the row tags and text overhead, and when the parser breaks out of the table it's still including the remaining "rows" as text.