Skip to content

Commit 6d4ec8e

Browse files
committed
Merge #53
53: Add fuzz target for html5ever r=frewsxcv Fixes #25 Does not compile currently as it exits with > ERROR: AddressSanitizer: heap-buffer-overflow […] > ACCESS of size 0 cf. rust-lang/rust#39882
2 parents cc7c15f + fb8966c commit 6d4ec8e

5 files changed

Lines changed: 174 additions & 0 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ members = [
99
"dns-parser",
1010
"encoding_rs",
1111
"flac",
12+
"html5ever",
1213
"httparse",
1314
"humantime",
1415
"image",

html5ever/Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "html5ever-targets"
3+
version = "0.0.0"
4+
publish = false
5+
6+
[dependencies]
7+
tendril = "0.2.2"
8+
html5ever = { git = "https://github.com/servo/html5ever" }
9+
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer-sys.git" }
10+
11+
[[bin]]
12+
name = "read_html"
13+
path = "read_html.rs"

html5ever/read_html.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// adapted from https://github.com/servo/html5ever/blob/00c3c41f77cf6fbf325140906c88e4153dd19020/examples/html2html.rs
2+
3+
#![no_main]
4+
5+
#[macro_use] extern crate libfuzzer_sys;
6+
extern crate tendril;
7+
extern crate html5ever;
8+
9+
use std::default::Default;
10+
use std::io::BufReader;
11+
12+
use html5ever::driver::ParseOpts;
13+
use html5ever::tree_builder::TreeBuilderOpts;
14+
use html5ever::{parse_document, serialize};
15+
use html5ever::tendril::TendrilSink;
16+
use html5ever::rcdom::RcDom;
17+
18+
fuzz_target!(|data| {
19+
let opts = ParseOpts {
20+
tree_builder: TreeBuilderOpts {
21+
drop_doctype: true,
22+
..Default::default()
23+
},
24+
..Default::default()
25+
};
26+
27+
let dom = parse_document(RcDom::default(), opts)
28+
.from_utf8()
29+
.read_from(&mut BufReader::new(data));
30+
31+
let dom = if let Ok(dom) = dom { dom } else { return; };
32+
33+
let mut out = Vec::with_capacity(data.len());
34+
let _ = serialize(&mut out, &dom.document, Default::default());
35+
});

html5ever/seeds/0001

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
</head>
9+
<body>
10+
hello world
11+
</body>
12+
</html>

html5ever/seeds/0002

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta name="generator" content="rustdoc">
7+
<meta name="description" content="API documentation for the Rust `serialize` fn in crate `html5ever`.">
8+
<meta name="keywords" content="rust, rustlang, rust-lang, serialize">
9+
10+
<title>html5ever::serialize::serialize - Rust</title>
11+
12+
<link rel="stylesheet" type="text/css" href="../../normalize.css">
13+
<link rel="stylesheet" type="text/css" href="../../rustdoc.css">
14+
<link rel="stylesheet" type="text/css" href="../../main.css">
15+
16+
17+
18+
19+
</head>
20+
<body class="rustdoc">
21+
<!--[if lte IE 8]>
22+
<div class="warning">
23+
This old browser is unsupported and will most likely display funky
24+
things.
25+
</div>
26+
<![endif]-->
27+
28+
29+
30+
<nav class="sidebar">
31+
32+
<p class='location'><a href='../index.html'>html5ever</a>::<wbr><a href='index.html'>serialize</a></p><script>window.sidebarCurrent = {name: 'serialize', ty: 'fn', relpath: ''};</script><script defer src="sidebar-items.js"></script>
33+
</nav>
34+
35+
<nav class="sub">
36+
<form class="search-form js-only">
37+
<div class="search-container">
38+
<input class="search-input" name="search"
39+
autocomplete="off"
40+
placeholder="Click or press ‘S’ to search, ‘?’ for more options…"
41+
type="search">
42+
</div>
43+
</form>
44+
</nav>
45+
46+
<section id='main' class="content fn">
47+
<h1 class='fqn'><span class='in-band'>Function <a href='../index.html'>html5ever</a>::<wbr><a href='index.html'>serialize</a>::<wbr><a class="fn" href=''>serialize</a></span><span class='out-of-band'><span id='render-detail'>
48+
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
49+
[<span class='inner'>&#x2212;</span>]
50+
</a>
51+
</span><a class='srclink' href='../../src/html5ever/serialize/mod.rs.html#27-32' title='goto source code'>[src]</a></span></h1>
52+
<pre class='rust fn'>pub fn serialize&lt;Wr:&nbsp;<a class="trait" href="../../std/io/trait.Write.html" title="trait std::io::Write">Write</a>, T:&nbsp;<a class="trait" href="../../html5ever/serialize/trait.Serializable.html" title="trait html5ever::serialize::Serializable">Serializable</a>&gt;(writer: &amp;mut Wr,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; node: &amp;T,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; opts: <a class="struct" href="../../html5ever/serialize/struct.SerializeOpts.html" title="struct html5ever::serialize::SerializeOpts">SerializeOpts</a>)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; -&gt; <a class="type" href="../../std/io/error/type.Result.html" title="type std::io::error::Result">Result</a>&lt;<a class="primitive" href="../../std/primitive.tuple.html">()</a>&gt;</pre></section>
53+
<section id='search' class="content hidden"></section>
54+
55+
<section class="footer"></section>
56+
57+
<aside id="help" class="hidden">
58+
<div>
59+
<h1 class="hidden">Help</h1>
60+
61+
<div class="shortcuts">
62+
<h2>Keyboard Shortcuts</h2>
63+
64+
<dl>
65+
<dt>?</dt>
66+
<dd>Show this help dialog</dd>
67+
<dt>S</dt>
68+
<dd>Focus the search field</dd>
69+
<dt>&larrb;</dt>
70+
<dd>Move up in search results</dd>
71+
<dt>&rarrb;</dt>
72+
<dd>Move down in search results</dd>
73+
<dt>&#9166;</dt>
74+
<dd>Go to active search result</dd>
75+
<dt>+</dt>
76+
<dd>Collapse/expand all sections</dd>
77+
</dl>
78+
</div>
79+
80+
<div class="infos">
81+
<h2>Search Tricks</h2>
82+
83+
<p>
84+
Prefix searches with a type followed by a colon (e.g.
85+
<code>fn:</code>) to restrict the search to a given type.
86+
</p>
87+
88+
<p>
89+
Accepted types are: <code>fn</code>, <code>mod</code>,
90+
<code>struct</code>, <code>enum</code>,
91+
<code>trait</code>, <code>type</code>, <code>macro</code>,
92+
and <code>const</code>.
93+
</p>
94+
95+
<p>
96+
Search functions by type signature (e.g.
97+
<code>vec -> usize</code> or <code>* -> vec</code>)
98+
</p>
99+
</div>
100+
</div>
101+
</aside>
102+
103+
104+
105+
<script>
106+
window.rootPath = "../../";
107+
window.currentCrate = "html5ever";
108+
</script>
109+
<script src="../../jquery.js"></script>
110+
<script src="../../main.js"></script>
111+
<script defer src="../../search-index.js"></script>
112+
</body>
113+
</html>

0 commit comments

Comments
 (0)