aboutsummaryrefslogtreecommitdiff
path: root/fuzz/fuzz_targets/fuzz_document_parse.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-04-08 08:42:01 +0200
committerMartin Fischer <martin@push-f.com>2021-04-08 15:40:37 +0200
commit57e7eefcbe6fb8c3dc4b01c707be9de4c34963a7 (patch)
tree6a9d296389bf3023396592c8514ed6712e011c7f /fuzz/fuzz_targets/fuzz_document_parse.rs
import https://github.com/servo/html5ever
commit d1206daa740305f55a5fa159e43eb33afc359cb4
Diffstat (limited to 'fuzz/fuzz_targets/fuzz_document_parse.rs')
-rw-r--r--fuzz/fuzz_targets/fuzz_document_parse.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/fuzz/fuzz_targets/fuzz_document_parse.rs b/fuzz/fuzz_targets/fuzz_document_parse.rs
new file mode 100644
index 0000000..17840de
--- /dev/null
+++ b/fuzz/fuzz_targets/fuzz_document_parse.rs
@@ -0,0 +1,35 @@
+#![no_main]
+use libfuzzer_sys::fuzz_target;
+
+use std::io::BufReader;
+use html5ever::driver::ParseOpts;
+use markup5ever_rcdom::{RcDom, SerializableHandle};
+use html5ever::tendril::TendrilSink;
+use html5ever::tree_builder::TreeBuilderOpts;
+use html5ever::{parse_document, serialize};
+
+// Target inspired by the Rust-Fuzz project
+// https://github.com/rust-fuzz/targets
+fuzz_target!(|data: &[u8]| {
+ let opts = ParseOpts {
+ tree_builder: TreeBuilderOpts {
+ drop_doctype: true,
+ ..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());
+});