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

Regex DOS fixes #387

Merged
merged 3 commits into from Jan 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/markdown2.py
Expand Up @@ -532,7 +532,7 @@ def parse_structured_value(value):

return tail

_emacs_oneliner_vars_pat = re.compile(r"-\*-\s*([^\r\n]*?)\s*-\*-", re.UNICODE)
_emacs_oneliner_vars_pat = re.compile(r"-\*-\s*(?:(\S[^\r\n]*?)([\r\n]\s*)?)?-\*-", re.UNICODE)
# This regular expression is intended to match blocks like this:
# PREFIX Local Variables: SUFFIX
# PREFIX mode: Tcl SUFFIX
Expand Down Expand Up @@ -892,8 +892,8 @@ def _do_numbering(self, text):
'''
# First pass to define all the references
self.regex_defns = re.compile(r'''
\[\#(\w+)\s* # the counter. Open square plus hash plus a word \1
([^@]*)\s* # Some optional characters, that aren't an @. \2
\[\#(\w+) # the counter. Open square plus hash plus a word \1
([^@]*) # Some optional characters, that aren't an @. \2
@(\w+) # the id. Should this be normed? \3
([^\]]*)\] # The rest of the text up to the terminating ] \4
''', re.VERBOSE)
Expand All @@ -908,7 +908,7 @@ def _do_numbering(self, text):
if len(match.groups()) != 4:
continue
counter = match.group(1)
text_before = match.group(2)
text_before = match.group(2).strip()
ref_id = match.group(3)
text_after = match.group(4)
number = counters.get(counter, 1)
Expand Down Expand Up @@ -1926,9 +1926,9 @@ def _do_code_blocks(self, text):

_fenced_code_block_re = re.compile(r'''
(?:\n+|\A\n?)
^```\s*?([\w+-]+)?\s*?\n # opening fence, $1 = optional lang
(.*?) # $2 = code block content
^```[ \t]*\n # closing fence
^```\s{0,99}([\w+-]+)?\s{0,99}\n # opening fence, $1 = optional lang
(.*?) # $2 = code block content
^```[ \t]*\n # closing fence
''', re.M | re.X | re.S)

def _fenced_code_block_sub(self, match):
Expand Down