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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test out simple generic fuzzing using traversal #1105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,21 @@ name = "fuzz_sparse_bit_set_encode"
path = "fuzz_targets/fuzz_sparse_bit_set_encode.rs"
test = false
doc = false

[[bin]]
name = "fuzz_gdef"
path = "fuzz_targets/fuzz_gdef.rs"
test = false
doc = false

[[bin]]
name = "fuzz_gpos"
path = "fuzz_targets/fuzz_gpos.rs"
test = false
doc = false

[[bin]]
name = "fuzz_gsub"
path = "fuzz_targets/fuzz_gsub.rs"
test = false
doc = false
7 changes: 7 additions & 0 deletions fuzz/fuzz_targets/fuzz_gdef.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![no_main]

mod traversal_fuzz;
use libfuzzer_sys::{fuzz_target, Corpus};
use read_fonts::tables::gdef::Gdef;

fuzz_target!(|data: &[u8]| -> Corpus { traversal_fuzz::try_traverse_table::<Gdef>(data, false) });
7 changes: 7 additions & 0 deletions fuzz/fuzz_targets/fuzz_gpos.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![no_main]

mod traversal_fuzz;
use libfuzzer_sys::{fuzz_target, Corpus};
use read_fonts::tables::gpos::Gpos;

fuzz_target!(|data: &[u8]| -> Corpus { traversal_fuzz::try_traverse_table::<Gpos>(data, false) });
7 changes: 7 additions & 0 deletions fuzz/fuzz_targets/fuzz_gsub.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![no_main]

mod traversal_fuzz;
use libfuzzer_sys::{fuzz_target, Corpus};
use read_fonts::tables::gsub::Gsub;

fuzz_target!(|data: &[u8]| -> Corpus { traversal_fuzz::try_traverse_table::<Gsub>(data, false) });
28 changes: 28 additions & 0 deletions fuzz/fuzz_targets/traversal_fuzz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::fmt::Debug;
use std::io::Write;

use libfuzzer_sys::Corpus;
use read_fonts::FontRead;

/// Reusable entry point to fuzz any table via traversal
///
/// To debug timeouts, set `print_output` to `true` (the output text will help
/// show where you're hitting a loop)
pub fn try_traverse_table<'a, T: FontRead<'a> + Debug>(
data: &'a [u8],
print_output: bool,
) -> Corpus {
match T::read(data.into()) {
Err(_) => Corpus::Reject,
Ok(table) => {
if print_output {
let _ = writeln!(std::io::stderr(), "{table:?}");
} else {
// if we don't want to see the output don't bother filling a buffer
let mut empty = std::io::empty();
write!(&mut empty, "{table:?}").unwrap();
}
Corpus::Keep
}
}
}