-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test out simple generic fuzzing using traversal
- Loading branch information
Showing
5 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |