Skip to content

Commit 36b06b8

Browse files
authored
Merge pull request #594 from Mrmaxmeier/fuzzer-cleanup
Cleanup fuzzers, add unresolved `relaxed_autolink_email_in_footnote` test
2 parents d2dd7c1 + 2224958 commit 36b06b8

File tree

14 files changed

+168
-106
lines changed

14 files changed

+168
-106
lines changed

fuzz/Cargo.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,15 @@ name = "gfm_footnotes"
6060
path = "fuzz_targets/gfm_footnotes.rs"
6161
test = false
6262
doc = false
63+
64+
[[bin]]
65+
name = "commonmark"
66+
path = "fuzz_targets/commonmark.rs"
67+
test = false
68+
doc = false
69+
70+
[[bin]]
71+
name = "parse"
72+
path = "fuzz_targets/parse.rs"
73+
test = false
74+
doc = false

fuzz/fuzz_targets/cli_default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use comrak::{markdown_to_html_with_plugins, plugins::syntect::SyntectAdapter, Pl
77
// Note that we end up fuzzing Syntect here.
88

99
fuzz_target!(|s: &str| {
10-
let adapter = SyntectAdapter::new("base16-ocean.dark");
10+
let adapter = SyntectAdapter::new(Some("base16-ocean.dark"));
1111

1212
let mut plugins = Plugins::default();
1313
plugins.render.codefence_syntax_highlighter = Some(&adapter);

fuzz/fuzz_targets/commonmark.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![no_main]
2+
use comrak::{markdown_to_commonmark, markdown_to_commonmark_xml, Options};
3+
use libfuzzer_sys::arbitrary::Arbitrary;
4+
use libfuzzer_sys::fuzz_target;
5+
6+
#[derive(Arbitrary, Debug)]
7+
struct Input<'a> {
8+
options: Options<'a>,
9+
markdown: &'a str,
10+
}
11+
12+
fuzz_target!(|input: Input| {
13+
if input.options.render.width > 100 || input.options.render.ol_width > 100 {
14+
return;
15+
}
16+
let _ = markdown_to_commonmark(input.markdown, &input.options);
17+
let _ = markdown_to_commonmark_xml(input.markdown, &input.options);
18+
});

fuzz/fuzz_targets/fuzz_options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use comrak::{markdown_to_html, Options};
77
#[derive(Debug, arbitrary::Arbitrary)]
88
struct FuzzInput<'s> {
99
s: &'s str,
10-
opts: Options,
10+
opts: Options<'s>,
1111
}
1212

1313
fuzz_target!(|i: FuzzInput| {

fuzz/fuzz_targets/gfm.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@ use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};
99
// options are routinely used by Commonmarker users.
1010

1111
fuzz_target!(|s: &str| {
12-
let mut extension = ExtensionOptions::default();
13-
extension.strikethrough = true;
14-
extension.tagfilter = true;
15-
extension.table = true;
16-
extension.autolink = true;
12+
let extension = ExtensionOptions {
13+
strikethrough: true,
14+
tagfilter: true,
15+
table: true,
16+
autolink: true,
17+
..Default::default()
18+
};
1719

18-
let mut render = RenderOptions::default();
19-
render.hardbreaks = true;
20-
render.github_pre_lang = true;
21-
render.unsafe_ = true;
20+
let render = RenderOptions {
21+
hardbreaks: true,
22+
github_pre_lang: true,
23+
unsafe_: true,
24+
..Default::default()
25+
};
2226

2327
markdown_to_html(
2428
s,

fuzz/fuzz_targets/gfm_footnotes.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};
99
// options are routinely used by Commonmarker users.
1010

1111
fuzz_target!(|s: &str| {
12-
let mut extension = ExtensionOptions::default();
13-
extension.strikethrough = true;
14-
extension.tagfilter = true;
15-
extension.table = true;
16-
extension.autolink = true;
17-
extension.footnotes = true;
12+
let extension = ExtensionOptions {
13+
strikethrough: true,
14+
tagfilter: true,
15+
table: true,
16+
autolink: true,
17+
footnotes: true,
18+
..Default::default()
19+
};
1820

19-
let mut render = RenderOptions::default();
20-
render.hardbreaks = true;
21-
render.github_pre_lang = true;
22-
render.unsafe_ = true;
21+
let render = RenderOptions {
22+
hardbreaks: true,
23+
github_pre_lang: true,
24+
unsafe_: true,
25+
..Default::default()
26+
};
2327

2428
markdown_to_html(
2529
s,

fuzz/fuzz_targets/gfm_sourcepos.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};
99
// options are routinely used by Commonmarker users.
1010

1111
fuzz_target!(|s: &str| {
12-
let mut extension = ExtensionOptions::default();
13-
extension.strikethrough = true;
14-
extension.tagfilter = true;
15-
extension.table = true;
16-
extension.autolink = true;
12+
let extension = ExtensionOptions {
13+
strikethrough: true,
14+
tagfilter: true,
15+
table: true,
16+
autolink: true,
17+
..Default::default()
18+
};
1719

18-
let mut render = RenderOptions::default();
19-
render.hardbreaks = true;
20-
render.github_pre_lang = true;
21-
render.unsafe_ = true;
22-
render.sourcepos = true;
20+
let render = RenderOptions {
21+
hardbreaks: true,
22+
github_pre_lang: true,
23+
unsafe_: true,
24+
sourcepos: true,
25+
..Default::default()
26+
};
2327

2428
markdown_to_html(
2529
s,

fuzz/fuzz_targets/parse.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#![no_main]
2+
use comrak::{parse_document, Arena, Options};
3+
use libfuzzer_sys::arbitrary::{self, Arbitrary};
4+
use libfuzzer_sys::fuzz_target;
5+
6+
#[derive(Arbitrary, Debug)]
7+
struct Input<'a> {
8+
options: Options<'a>,
9+
markdown: &'a str,
10+
}
11+
12+
fuzz_target!(|input: Input| {
13+
let arena = Arena::new();
14+
let _ = parse_document(&arena, input.markdown, &input.options);
15+
});

fuzz/fuzz_targets/quadratic.rs

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(div_duration)]
21
#![feature(int_roundings)]
32
#![no_main]
43
use comrak::{
@@ -35,6 +34,7 @@ enum Markdown {
3534
// foofoo
3635
// foofoofoo
3736
// foofoofoofoo
37+
#[allow(clippy::enum_variant_names)]
3838
Markdown {
3939
markdown: String,
4040
},
@@ -92,11 +92,11 @@ impl Markdown {
9292

9393
// Place the markdown in `output`
9494
for _ in 0..iterations {
95-
output.push_str(&prefix)
95+
output.push_str(prefix)
9696
}
97-
output.push_str(&markdown);
97+
output.push_str(markdown);
9898
for _ in 0..iterations {
99-
output.push_str(&suffix)
99+
output.push_str(suffix)
100100
}
101101
}
102102
output
@@ -117,9 +117,9 @@ impl Markdown {
117117

118118
// Place the markdown in `output`
119119
for _ in 0..iterations {
120-
output.push_str(&prefix)
120+
output.push_str(prefix)
121121
}
122-
output.push_str(&markdown);
122+
output.push_str(markdown);
123123
}
124124
output
125125
}
@@ -131,7 +131,7 @@ impl Markdown {
131131
}
132132

133133
fn should_fuzz_string(s: &str) -> bool {
134-
if s.len() == 0 {
134+
if s.is_empty() {
135135
// Repeating a zero-length string is useless
136136
return false;
137137
}
@@ -147,18 +147,18 @@ impl Markdown {
147147
/// A filter to guiding the fuzzer. The fuzzer will skip any input which fails this predicate
148148
fn should_fuzz(&self) -> bool {
149149
match self {
150-
Markdown::Markdown { markdown } => Markdown::should_fuzz_string(&markdown),
150+
Markdown::Markdown { markdown } => Markdown::should_fuzz_string(markdown),
151151
Markdown::Sandwich {
152152
prefix,
153153
markdown,
154154
suffix,
155155
} => {
156-
Markdown::should_fuzz_string(&prefix)
157-
&& Markdown::should_fuzz_string(&markdown)
158-
&& Markdown::should_fuzz_string(&suffix)
156+
Markdown::should_fuzz_string(prefix)
157+
&& Markdown::should_fuzz_string(markdown)
158+
&& Markdown::should_fuzz_string(suffix)
159159
}
160160
Markdown::Tree { prefix, markdown } => {
161-
Markdown::should_fuzz_string(&prefix) && Markdown::should_fuzz_string(&markdown)
161+
Markdown::should_fuzz_string(prefix) && Markdown::should_fuzz_string(markdown)
162162
}
163163
}
164164
}
@@ -172,7 +172,7 @@ struct FuzzOptions {
172172
}
173173

174174
impl FuzzOptions {
175-
fn to_options(&self) -> Options {
175+
fn to_options(&self) -> Options<'_> {
176176
Options {
177177
extension: self.extension.to_options(),
178178
parse: self.parse.to_options(),
@@ -204,29 +204,30 @@ struct FuzzExtensionOptions {
204204
}
205205

206206
impl FuzzExtensionOptions {
207-
fn to_options(&self) -> ExtensionOptions {
208-
let mut extension = ExtensionOptions::default();
209-
extension.strikethrough = self.strikethrough;
210-
extension.tagfilter = self.tagfilter;
211-
extension.table = self.table;
212-
extension.autolink = self.autolink;
213-
extension.tasklist = self.tasklist;
214-
extension.superscript = self.superscript;
215-
extension.footnotes = self.footnotes;
216-
extension.description_lists = self.description_lists;
217-
extension.multiline_block_quotes = self.multiline_block_quotes;
218-
extension.math_dollars = self.math_dollars;
219-
extension.math_code = self.math_code;
220-
extension.shortcodes = self.shortcodes;
221-
extension.wikilinks_title_after_pipe = self.wikilinks_title_after_pipe;
222-
extension.wikilinks_title_before_pipe = self.wikilinks_title_before_pipe;
223-
extension.underline = self.underline;
224-
extension.spoiler = self.spoiler;
225-
extension.greentext = self.greentext;
226-
extension.alerts = self.alerts;
227-
extension.front_matter_delimiter = None;
228-
extension.header_ids = None;
229-
extension
207+
fn to_options(&self) -> ExtensionOptions<'_> {
208+
ExtensionOptions {
209+
strikethrough: self.strikethrough,
210+
tagfilter: self.tagfilter,
211+
table: self.table,
212+
autolink: self.autolink,
213+
tasklist: self.tasklist,
214+
superscript: self.superscript,
215+
footnotes: self.footnotes,
216+
description_lists: self.description_lists,
217+
multiline_block_quotes: self.multiline_block_quotes,
218+
math_dollars: self.math_dollars,
219+
math_code: self.math_code,
220+
shortcodes: self.shortcodes,
221+
wikilinks_title_after_pipe: self.wikilinks_title_after_pipe,
222+
wikilinks_title_before_pipe: self.wikilinks_title_before_pipe,
223+
underline: self.underline,
224+
spoiler: self.spoiler,
225+
greentext: self.greentext,
226+
alerts: self.alerts,
227+
front_matter_delimiter: None,
228+
header_ids: None,
229+
..Default::default()
230+
}
230231
}
231232
}
232233

@@ -238,13 +239,14 @@ struct FuzzParseOptions {
238239
}
239240

240241
impl FuzzParseOptions {
241-
fn to_options(&self) -> ParseOptions {
242-
let mut parse = ParseOptions::default();
243-
parse.smart = self.smart;
244-
parse.default_info_string = None;
245-
parse.relaxed_tasklist_matching = self.relaxed_tasklist_matching;
246-
parse.relaxed_autolinks = self.relaxed_autolinks;
247-
parse
242+
fn to_options(&self) -> ParseOptions<'_> {
243+
ParseOptions {
244+
smart: self.smart,
245+
default_info_string: None,
246+
relaxed_tasklist_matching: self.relaxed_tasklist_matching,
247+
relaxed_autolinks: self.relaxed_autolinks,
248+
..Default::default()
249+
}
248250
}
249251
}
250252

@@ -263,17 +265,18 @@ struct FuzzRenderOptions {
263265

264266
impl FuzzRenderOptions {
265267
fn to_options(&self) -> RenderOptions {
266-
let mut render = RenderOptions::default();
267-
render.hardbreaks = self.hardbreaks;
268-
render.github_pre_lang = self.github_pre_lang;
269-
render.full_info_string = self.full_info_string;
270-
render.width = self.width;
271-
render.unsafe_ = self.unsafe_;
272-
render.escape = self.escape;
273-
render.list_style = self.list_style;
274-
render.sourcepos = self.sourcepos;
275-
render.escaped_char_spans = self.escaped_char_spans;
276-
render
268+
RenderOptions {
269+
hardbreaks: self.hardbreaks,
270+
github_pre_lang: self.github_pre_lang,
271+
full_info_string: self.full_info_string,
272+
width: self.width,
273+
unsafe_: self.unsafe_,
274+
escape: self.escape,
275+
list_style: self.list_style,
276+
sourcepos: self.sourcepos,
277+
escaped_char_spans: self.escaped_char_spans,
278+
..Default::default()
279+
}
277280
}
278281
}
279282

src/html.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,7 @@ fn render_code_block<'a, T>(
577577

578578
highlighter.write_highlighted(
579579
context,
580-
match std::str::from_utf8(&info[..first_tag]) {
581-
Ok(lang) => Some(lang),
582-
Err(_) => None,
583-
},
580+
std::str::from_utf8(&info[..first_tag]).ok(),
584581
&ncb.literal,
585582
)?;
586583

0 commit comments

Comments
 (0)