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

Quadratic blowup on pathological input. #24

Closed
DemiMarie opened this issue Jul 10, 2017 · 5 comments
Closed

Quadratic blowup on pathological input. #24

DemiMarie opened this issue Jul 10, 2017 · 5 comments
Assignees

Comments

@DemiMarie
Copy link
Contributor

This takes ~1s on my machine:

perl -e 'print "_a* " x 40000' | time comrak >/dev/null

This allows a denial of service in any application using Comrak to process untrusted input, and thus prevents it from being used for that purpose, forcing the use of a C library such as cmark or MD4C instead.

@kivikakk
Copy link
Owner

This may be related to commonmark/cmark#178 — I'll look into it and work out a fix shortly. Thank you! ❤️

@kivikakk kivikakk self-assigned this Jul 11, 2017
@kivikakk
Copy link
Owner

Turns out it's unrelated to that — it's instead to do with the translation of process_emphasis into Rust. I believe we're not adjusting indices into openers_bottom everywhere we should be; the original just uses a bunch of linked lists floating around and doesn't need to worry about such things.

@kivikakk
Copy link
Owner

Not even that — we're removing from all over self.delimiters in process_emphasis, which is a Vec. Because we're not just popping from the back, end up doing large amounts of shifts of data, which adds up to quadratic in its complexity. I'll likely need to redo this as linked lists/as an arena.

kivikakk added a commit that referenced this issue Jul 18, 2017
kivikakk added a commit that referenced this issue Jul 18, 2017
@kivikakk
Copy link
Owner

Thanks so much; this is fixed!

@kivikakk
Copy link
Owner

kahekkass ~/kivikakk/comrak quadratic$ perl -e 'print "_a* " x 80000' | time target/release/comrak >/dev/null; perl -e 'print "_a* " x 640000' | time target/release/comrak >/dev/null
        0.08 real         0.05 user         0.02 sys
        0.63 real         0.46 user         0.16 sys

brson pushed a commit to brson/comrak that referenced this issue Jul 3, 2018
* Fix for format range error

* Eliminate breaks and unused syntax

* Remove breaks and fix blockquote behavior

* Fix table error and format to work for nesting
brson pushed a commit to brson/comrak that referenced this issue Jul 3, 2018
* Fix for format range error

* Eliminate breaks and unused syntax

* Remove breaks and fix blockquote behavior

* Fix table error and format to work for nesting
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

No branches or pull requests

2 participants