Skip to content

Commit

Permalink
馃И Fix fuzzing test failures (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisjsewell committed Mar 14, 2023
1 parent 34876b1 commit 07e9b7d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
5 changes: 4 additions & 1 deletion markdown_it/rules_block/blockquote.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def blockquote(state: StateBlock, startLine: int, endLine: int, silent: bool):
return False

# check the block quote marker
if state.srcCharCode[pos] != 0x3E: # /* > */
try:
if state.srcCharCode[pos] != 0x3E: # /* > */
return False
except IndexError:
return False
pos += 1

Expand Down
7 changes: 5 additions & 2 deletions markdown_it/rules_block/fence.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ def fence(state: StateBlock, startLine: int, endLine: int, silent: bool):
# test
break

if state.srcCharCode[pos] != marker:
continue
try:
if state.srcCharCode[pos] != marker:
continue
except IndexError:
break

if state.sCount[nextLine] - state.blkIndent >= 4:
# closing fence should be indented less than 4 spaces
Expand Down
5 changes: 4 additions & 1 deletion markdown_it/rules_block/hr.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def hr(state: StateBlock, startLine: int, endLine: int, silent: bool):
if state.sCount[startLine] - state.blkIndent >= 4:
return False

marker = state.srcCharCode[pos]
try:
marker = state.srcCharCode[pos]
except IndexError:
return False
pos += 1

# Check hr marker: /* * */ /* - */ /* _ */
Expand Down
5 changes: 4 additions & 1 deletion markdown_it/rules_block/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ def skipBulletListMarker(state: StateBlock, startLine: int):
pos = state.bMarks[startLine] + state.tShift[startLine]
maximum = state.eMarks[startLine]

marker = state.srcCharCode[pos]
try:
marker = state.srcCharCode[pos]
except IndexError:
return -1
pos += 1
# Check bullet /* * */ /* - */ /* + */
if marker != 0x2A and marker != 0x2D and marker != 0x2B:
Expand Down
24 changes: 24 additions & 0 deletions tests/test_fuzzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
These tests are in response to reports from:
https://github.com/google/oss-fuzz/tree/master/projects/markdown-it-py
In the future, perhaps atheris could be directly used here,
but it was not directly apparent how to integrate it into pytest.
"""
import pytest

from markdown_it import MarkdownIt

TESTS = {
55363: ">```\n>",
55367: ">-\n>\n>",
# 55371: "[](so&#4禄0;!" TODO this did not fail
# 55401: "?c_" * 100_000 TODO this did not fail
}


@pytest.mark.parametrize("raw_input", TESTS.values(), ids=TESTS.keys())
def test_fuzzing(raw_input):
md = MarkdownIt()
md.parse(raw_input)
print(md.render(raw_input))

0 comments on commit 07e9b7d

Please sign in to comment.