Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/markdown2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2574,7 +2574,9 @@ class GFMItalicAndBoldProcessor(Extra):

def run(self, text):
nesting = True
while nesting:
orig_text = ""
while nesting and orig_text != _hash_text(text):
orig_text = _hash_text(text)
nesting = False

opens = {'*': [], '_': []}
Expand Down
24 changes: 15 additions & 9 deletions test/test_redos.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,23 @@ def issue_633():
# https://github.com/trentm/python-markdown2/issues/633
return '<p m="1"' * 2500 + " " * 5000 + "</div"

def issue_668():
# https://github.com/trentm/python-markdown2/issues/668
# not technically a redos, but still an error that caused a DOS
return 'a_b **x***y* c_d'


# whack everything in a dict for easy lookup later on
CASES = {
fn.__name__: fn
for fn in [
pull_387_example_1,
pull_387_example_2,
pull_387_example_3,
pull_402,
issue493,
issue_633,
fn.__name__: (fn, extras)
for fn, extras in [
(pull_387_example_1, None),
(pull_387_example_2, None),
(pull_387_example_3, None),
(pull_402, None),
(issue493, None),
(issue_633, None),
(issue_668, ['code-friendly']),
]
}

Expand All @@ -60,7 +66,7 @@ def issue_633():
sys.path.insert(0, str(LIB_DIR))
from markdown2 import markdown

markdown(testcase())
markdown(testcase[0](), extras=testcase[1])
sys.exit(0)

print("-- ReDoS tests")
Expand Down