Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
108: Add svgtypes targets r=frewsxcv a=killercup

Taken from their respective repos so we can easily run them against the other fuzzers

Co-authored-by: Pascal Hertleif <[email protected]>
  • Loading branch information
bors[bot] and killercup committed Apr 27, 2018
2 parents fb6e0b5 + 9b795d7 commit 7987f0f
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
3 changes: 3 additions & 0 deletions common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ uuid = { git = "https://github.com/rust-lang-nursery/uuid" }
xml-rs = { git = "https://github.com/netvl/xml-rs.git" }
zip = { git = "https://github.com/mvdnes/zip-rs" }
zopfli = { git = "https://github.com/carols10cents/zopfli" }
svgtypes = { git = "https://github.com/RazrFalcon/svgtypes" }
xmlparser = { git = "https://github.com/RazrFalcon/xmlparser" }
usvg = { git = "https://github.com/RazrFalcon/usvg" }
117 changes: 117 additions & 0 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ extern crate uuid;
extern crate xml;
extern crate zip;
extern crate zopfli;
extern crate svgtypes;
extern crate xmlparser;
extern crate usvg;

#[inline(always)]
pub fn fuzz_brotli_read(data: &[u8]) {
Expand Down Expand Up @@ -776,3 +779,117 @@ pub fn fuzz_zopfli_compress(data: &[u8]) {
let _ = zopfli::compress(&options, &output_type, &data, &mut res);
}
}

#[inline(always)]
pub fn fuzz_svgtypes_color(data: &[u8]) {
use std::str;
use std::str::FromStr;

if let Ok(s) = str::from_utf8(data) {
// Must not panic.
let _ = svgtypes::Color::from_str(s);
}
}

#[inline(always)]
pub fn fuzz_svgtypes_length(data: &[u8]) {
use std::str;
use std::str::FromStr;
use svgtypes::{Length, Error};

if let Ok(s) = str::from_utf8(data) {
if let Err(e) = Length::from_str(s) {
match e {
Error::InvalidNumber(_) => {}
_ => panic!("{:?}", e),
}
}
}
}

#[inline(always)]
pub fn fuzz_svgtypes_path(data: &[u8]) {
use std::str;

if let Ok(s) = str::from_utf8(data) {
// Must not panic.
let mut n = 0;
for _ in svgtypes::PathParser::from(s) {
n += 1;

if n == 1000 {
panic!("endless loop");
}
}
}
}

#[inline(always)]
pub fn fuzz_svgtypes_style(data: &[u8]) {
use std::str;

if let Ok(s) = str::from_utf8(data) {
// Must not panic.
let mut n = 0;
for _ in svgtypes::StyleParser::from(s) {
n += 1;

if n == 1000 {
panic!("endless loop");
}
}
}
}

#[inline(always)]
pub fn fuzz_svgtypes_transforms(data: &[u8]) {
use std::str;

if let Ok(s) = str::from_utf8(data) {
// Must not panic.
let mut n = 0;
for _ in svgtypes::TransformListParser::from(s) {
n += 1;

if n == 1000 {
panic!("endless loop");
}
}
}
}

#[inline(always)]
pub fn fuzz_xmlparser_unescape(data: &[u8]) {
use std::str;
use xmlparser::{TextUnescape, XmlSpace};

if let Ok(s) = str::from_utf8(data) {
let _ = TextUnescape::unescape(s, XmlSpace::Default);
let _ = TextUnescape::unescape(s, XmlSpace::Preserve);
}
}

#[inline(always)]
pub fn fuzz_xmlparser_xml(data: &[u8]) {
use std::str;

if let Ok(text) = str::from_utf8(data) {
let mut n = 0;
for _ in xmlparser::Tokenizer::from(text) {
n += 1;

if n == 1000 {
panic!("endless loop");
}
}
}
}

#[inline(always)]
pub fn fuzz_usvg_parse_tree(data: &[u8]) {
use std::str;

if let Ok(text) = str::from_utf8(data) {
let _ = usvg::parse_tree_from_data(text, &usvg::Options::default());
}
}

0 comments on commit 7987f0f

Please sign in to comment.