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

catastrophic backtracking in options-list regex #40

Closed
asottile opened this issue Sep 16, 2023 · 1 comment · Fixed by #42
Closed

catastrophic backtracking in options-list regex #40

asottile opened this issue Sep 16, 2023 · 1 comment · Fixed by #42

Comments

@asottile
Copy link

this regex causes catastrophic backtracking leading to denial-of-service for particularly written files --

"match": "^((?:-\\w|--[\\w-]+|/\\w+)(?:,? ?[\\w-]+)*)(?: |\\t|$)",

here's a small rst example from cpython:

The decimal module now requires libmpdec-2.5.0. Users of
--with-system-libmpdec should update their system library.

when attempting to match the second line the engine will recurse ~essentially forever (libonig has a boundary case to prevent this and raises an error)

I'm a little unfamiliar with what this is attempting to match -- but converting the second group to an atomic group (?>: seems to make the regex terminate quickly rather than spinning

trond-snekvik added a commit that referenced this issue Sep 17, 2023
The options list only supported parts of the options list syntax,
missing angle brackets around placeholders and several corner cases in
the alias syntax.

This commit fixes all known issues including #40, and adds a test case
specifically for options lists.
@trond-snekvik
Copy link
Owner

Hey, thanks for reporting, and thanks for the fix.

I can confirm that the fix does resolve the issue, but as I was writing a test case for this, I found a few other flaws in the options list regex. I made a PR to fix all issues here: #42.

For reference, the options list entry covers this concept: https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#option-lists

trond-snekvik added a commit that referenced this issue Sep 17, 2023
The options list only supported parts of the options list syntax,
missing angle brackets around placeholders and several corner cases in
the alias syntax.

This commit fixes all known issues including #40, and adds a test case
specifically for options lists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants