Skip to content

Commit

Permalink
fuzz: add broken link callback to all_options; cargo fmt.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed Jul 11, 2024
1 parent ad6f360 commit aa18a1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
20 changes: 16 additions & 4 deletions fuzz/fuzz_targets/all_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
use libfuzzer_sys::fuzz_target;

use comrak::{
markdown_to_html, ExtensionOptions, Options, ParseOptions,
RenderOptions, ListStyleType,
markdown_to_html, BrokenLinkReference, ExtensionOptions, ListStyleType, Options, ParseOptions,
RenderOptions, ResolvedReference,
};
use std::sync::{Arc, Mutex};

fuzz_target!(|s: &str| {
let mut extension = ExtensionOptions::default();
Expand All @@ -28,12 +29,19 @@ fuzz_target!(|s: &str| {
extension.underline = true;
extension.spoiler = true;
extension.greentext = true;

let mut parse = ParseOptions::default();
parse.smart = true;
parse.default_info_string = Some("rust".to_string());
parse.relaxed_tasklist_matching = true;
parse.relaxed_autolinks = true;
let mut cb = |link_ref: BrokenLinkReference| {
Some(ResolvedReference {
url: link_ref.normalized.to_string(),
title: link_ref.original.to_string(),
})
};
parse.broken_link_callback = Some(Arc::new(Mutex::new(&mut cb)));

let mut render = RenderOptions::default();
render.hardbreaks = true;
Expand All @@ -50,6 +58,10 @@ fuzz_target!(|s: &str| {

markdown_to_html(
s,
&Options { extension, parse, render },
&Options {
extension,
parse,
render,
},
);
});
4 changes: 1 addition & 3 deletions fuzz/fuzz_targets/cli_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

use libfuzzer_sys::fuzz_target;

use comrak::{
markdown_to_html_with_plugins, plugins::syntect::SyntectAdapter, Plugins,
};
use comrak::{markdown_to_html_with_plugins, plugins::syntect::SyntectAdapter, Plugins};

// Note that we end up fuzzing Syntect here.

Expand Down
17 changes: 4 additions & 13 deletions fuzz/fuzz_targets/quadratic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
#![feature(int_roundings)]
#![no_main]
use comrak::{
markdown_to_html, markdown_to_commonmark, markdown_to_commonmark_xml,
ExtensionOptions, Options, ParseOptions,
RenderOptions, ListStyleType,
markdown_to_commonmark, markdown_to_commonmark_xml, markdown_to_html, ExtensionOptions,
ListStyleType, Options, ParseOptions, RenderOptions,
};
use libfuzzer_sys::arbitrary::{self, Arbitrary};
use libfuzzer_sys::fuzz_target;
Expand Down Expand Up @@ -297,18 +296,10 @@ fn fuzz_one_input(input: &Input, num_bytes: usize) -> (usize, Duration, f64) {
let duration_per_byte = duration.as_secs_f64() / (byte_length as f64);

if DEBUG {
println!(
"do_one: {} bytes, duration = {:?}",
byte_length,
duration
);
println!("do_one: {} bytes, duration = {:?}", byte_length, duration);
}

(
byte_length,
duration,
duration_per_byte
)
(byte_length, duration, duration_per_byte)
}

/// The maximum number of steps to run in the main fuzzing loop below.
Expand Down

0 comments on commit aa18a1d

Please sign in to comment.