-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test(fuzz): fuzz xml5ever * style: drop newline on */fuzz/.gitignore
- Loading branch information
Showing
4 changed files
with
65 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
|
||
target | ||
corpus | ||
artifacts |
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,3 @@ | ||
target | ||
corpus | ||
artifacts |
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,27 @@ | ||
|
||
[package] | ||
name = "xml5ever-fuzz" | ||
version = "0.0.0" | ||
authors = ["David Korczynski <david@adalogics.com>"] | ||
publish = false | ||
edition = "2018" | ||
|
||
[package.metadata] | ||
cargo-fuzz = true | ||
|
||
[dependencies] | ||
libfuzzer-sys = "0.4.0" | ||
|
||
[dependencies.xml5ever] | ||
path = ".." | ||
|
||
[dependencies.markup5ever_rcdom] | ||
path = "../../rcdom/" | ||
|
||
# Prevent this from interfering with workspaces | ||
[workspace] | ||
members = ["."] | ||
|
||
[[bin]] | ||
name = "fuzz_document_parse" | ||
path = "fuzz_targets/fuzz_document_parse.rs" |
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,35 @@ | ||
#![no_main] | ||
use libfuzzer_sys::fuzz_target; | ||
|
||
use markup5ever_rcdom::{RcDom, SerializableHandle}; | ||
use std::io::BufReader; | ||
use xml5ever::driver::parse_document; | ||
use xml5ever::driver::XmlParseOpts; | ||
use xml5ever::serialize::serialize; | ||
use xml5ever::tendril::TendrilSink; | ||
use xml5ever::tree_builder::XmlTreeBuilderOpts; | ||
|
||
// Target inspired by the Rust-Fuzz project | ||
// https://github.com/rust-fuzz/targets | ||
fuzz_target!(|data: &[u8]| { | ||
let opts = XmlParseOpts { | ||
tree_builder: XmlTreeBuilderOpts { | ||
..Default::default() | ||
}, | ||
..Default::default() | ||
}; | ||
|
||
let dom = parse_document(RcDom::default(), opts) | ||
.from_utf8() | ||
.read_from(&mut BufReader::new(data)); | ||
|
||
let dom = if let Ok(dom) = dom { | ||
dom | ||
} else { | ||
return; | ||
}; | ||
|
||
let mut out = std::io::sink(); | ||
let document: SerializableHandle = dom.document.into(); | ||
let _ = serialize(&mut out, &document, Default::default()); | ||
}); |