Skip to content

Commit 7987f0f

Browse files
bors[bot]killercup
andcommitted
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]>
2 parents fb6e0b5 + 9b795d7 commit 7987f0f

File tree

2 files changed

+120
-0
lines changed

2 files changed

+120
-0
lines changed

common/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ uuid = { git = "https://github.com/rust-lang-nursery/uuid" }
4242
xml-rs = { git = "https://github.com/netvl/xml-rs.git" }
4343
zip = { git = "https://github.com/mvdnes/zip-rs" }
4444
zopfli = { git = "https://github.com/carols10cents/zopfli" }
45+
svgtypes = { git = "https://github.com/RazrFalcon/svgtypes" }
46+
xmlparser = { git = "https://github.com/RazrFalcon/xmlparser" }
47+
usvg = { git = "https://github.com/RazrFalcon/usvg" }

common/src/lib.rs

+117
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ extern crate uuid;
3636
extern crate xml;
3737
extern crate zip;
3838
extern crate zopfli;
39+
extern crate svgtypes;
40+
extern crate xmlparser;
41+
extern crate usvg;
3942

4043
#[inline(always)]
4144
pub fn fuzz_brotli_read(data: &[u8]) {
@@ -776,3 +779,117 @@ pub fn fuzz_zopfli_compress(data: &[u8]) {
776779
let _ = zopfli::compress(&options, &output_type, &data, &mut res);
777780
}
778781
}
782+
783+
#[inline(always)]
784+
pub fn fuzz_svgtypes_color(data: &[u8]) {
785+
use std::str;
786+
use std::str::FromStr;
787+
788+
if let Ok(s) = str::from_utf8(data) {
789+
// Must not panic.
790+
let _ = svgtypes::Color::from_str(s);
791+
}
792+
}
793+
794+
#[inline(always)]
795+
pub fn fuzz_svgtypes_length(data: &[u8]) {
796+
use std::str;
797+
use std::str::FromStr;
798+
use svgtypes::{Length, Error};
799+
800+
if let Ok(s) = str::from_utf8(data) {
801+
if let Err(e) = Length::from_str(s) {
802+
match e {
803+
Error::InvalidNumber(_) => {}
804+
_ => panic!("{:?}", e),
805+
}
806+
}
807+
}
808+
}
809+
810+
#[inline(always)]
811+
pub fn fuzz_svgtypes_path(data: &[u8]) {
812+
use std::str;
813+
814+
if let Ok(s) = str::from_utf8(data) {
815+
// Must not panic.
816+
let mut n = 0;
817+
for _ in svgtypes::PathParser::from(s) {
818+
n += 1;
819+
820+
if n == 1000 {
821+
panic!("endless loop");
822+
}
823+
}
824+
}
825+
}
826+
827+
#[inline(always)]
828+
pub fn fuzz_svgtypes_style(data: &[u8]) {
829+
use std::str;
830+
831+
if let Ok(s) = str::from_utf8(data) {
832+
// Must not panic.
833+
let mut n = 0;
834+
for _ in svgtypes::StyleParser::from(s) {
835+
n += 1;
836+
837+
if n == 1000 {
838+
panic!("endless loop");
839+
}
840+
}
841+
}
842+
}
843+
844+
#[inline(always)]
845+
pub fn fuzz_svgtypes_transforms(data: &[u8]) {
846+
use std::str;
847+
848+
if let Ok(s) = str::from_utf8(data) {
849+
// Must not panic.
850+
let mut n = 0;
851+
for _ in svgtypes::TransformListParser::from(s) {
852+
n += 1;
853+
854+
if n == 1000 {
855+
panic!("endless loop");
856+
}
857+
}
858+
}
859+
}
860+
861+
#[inline(always)]
862+
pub fn fuzz_xmlparser_unescape(data: &[u8]) {
863+
use std::str;
864+
use xmlparser::{TextUnescape, XmlSpace};
865+
866+
if let Ok(s) = str::from_utf8(data) {
867+
let _ = TextUnescape::unescape(s, XmlSpace::Default);
868+
let _ = TextUnescape::unescape(s, XmlSpace::Preserve);
869+
}
870+
}
871+
872+
#[inline(always)]
873+
pub fn fuzz_xmlparser_xml(data: &[u8]) {
874+
use std::str;
875+
876+
if let Ok(text) = str::from_utf8(data) {
877+
let mut n = 0;
878+
for _ in xmlparser::Tokenizer::from(text) {
879+
n += 1;
880+
881+
if n == 1000 {
882+
panic!("endless loop");
883+
}
884+
}
885+
}
886+
}
887+
888+
#[inline(always)]
889+
pub fn fuzz_usvg_parse_tree(data: &[u8]) {
890+
use std::str;
891+
892+
if let Ok(text) = str::from_utf8(data) {
893+
let _ = usvg::parse_tree_from_data(text, &usvg::Options::default());
894+
}
895+
}

0 commit comments

Comments
 (0)