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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃И Fix fuzzing test failures #254

Merged
merged 2 commits into from
Mar 14, 2023
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
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))