Skip to content

Commit

Permalink
Avoid crashing on cyclical footnotes
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Nov 23, 2023
1 parent b8d6487 commit e6caf75
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions fuzz/fuzz_targets/pandoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ fuzz_target!(|text: String| {
if text.contains("`") {
return;
}
if text.contains("[^ ") {
return;
}
if text.contains("[^\t") {
return;
}
if text.contains("[^\n") {
return;
}
if text.contains("[^\r") {
return;
}

if text.bytes().any(|b| b > 127) {
return;
Expand Down Expand Up @@ -62,13 +74,13 @@ fuzz_target!(|text: String| {
match event {
Event::Start(Tag::FootnoteDefinition(id)) => {
if id.starts_with("\n") || id.ends_with("\n") || id.starts_with("\r") || id.ends_with("\r") || id.starts_with(" ") || id.starts_with("\t") || id.contains(" ") || id.contains("\t ") || id.contains(" \t") || id.contains("\t\t") || id.ends_with(" ") || id.ends_with("\t") { return };
footstack.push(id.to_string());
footstack.push(id.trim().to_string());
}
Event::End(TagEnd::FootnoteDefinition) => {
footstack.pop();
}
Event::FootnoteReference(id) => {
if footstack.contains(&id.to_string()) {
if footstack.contains(&id.trim().to_string()) {
return;
}
}
Expand Down

0 comments on commit e6caf75

Please sign in to comment.