diff --git a/common/Cargo.toml b/common/Cargo.toml index d53c5fb..6d9c153 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -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" } diff --git a/common/src/lib.rs b/common/src/lib.rs index 886ca42..9af3a22 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -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]) { @@ -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()); + } +}