diff --git a/fuzz/.gitignore b/fuzz/.gitignore new file mode 100644 index 00000000..ff07c07d --- /dev/null +++ b/fuzz/.gitignore @@ -0,0 +1,3 @@ +target +corpus +artifacts \ No newline at end of file diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml new file mode 100644 index 00000000..18ca4657 --- /dev/null +++ b/fuzz/Cargo.toml @@ -0,0 +1,36 @@ +[package] +name = "oxigraph-fuzz" +version = "0.0.0" +authors = ["Automatically generated"] +publish = false +edition = "2021" + +[package.metadata] +cargo-fuzz = true + +[dependencies] +libfuzzer-sys = "0.4" +spargebra = { path = "../lib/spargebra", features = ["rdf-star"] } +sparesults = { path = "../lib/sparesults", features = ["rdf-star"] } + +[workspace] + +[[bin]] +name = "sparql_query" +path = "fuzz_targets/sparql_query.rs" + +[[bin]] +name = "sparql_update" +path = "fuzz_targets/sparql_update.rs" + +[[bin]] +name = "sparql_results_json" +path = "fuzz_targets/sparql_results_json.rs" + +[[bin]] +name = "sparql_results_xml" +path = "fuzz_targets/sparql_results_xml.rs" + +[[bin]] +name = "sparql_results_tsv" +path = "fuzz_targets/sparql_results_tsv.rs" diff --git a/fuzz/fuzz_targets/sparql_query.rs b/fuzz/fuzz_targets/sparql_query.rs new file mode 100644 index 00000000..b0286f6a --- /dev/null +++ b/fuzz/fuzz_targets/sparql_query.rs @@ -0,0 +1,10 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; +use spargebra::Query; +use std::str; + +fuzz_target!(|data: &[u8]| { + if let Ok(data) = str::from_utf8(data) { + Query::parse(data, None); + } +}); diff --git a/fuzz/fuzz_targets/sparql_results_json.rs b/fuzz/fuzz_targets/sparql_results_json.rs new file mode 100644 index 00000000..c5b4ddcb --- /dev/null +++ b/fuzz/fuzz_targets/sparql_results_json.rs @@ -0,0 +1,15 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; +use sparesults::{QueryResultsFormat, QueryResultsParser, QueryResultsReader}; + +fuzz_target!(|data: &[u8]| { + let parser = QueryResultsParser::from_format(QueryResultsFormat::Json); + if let Ok(QueryResultsReader::Solutions(solutions)) = parser.read_results(data) { + for s in solutions { + if s.is_err() { + // TODO: avoid infinite loop of errors + break; + } + } + } +}); diff --git a/fuzz/fuzz_targets/sparql_results_tsv.rs b/fuzz/fuzz_targets/sparql_results_tsv.rs new file mode 100644 index 00000000..ec69ab94 --- /dev/null +++ b/fuzz/fuzz_targets/sparql_results_tsv.rs @@ -0,0 +1,10 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; +use sparesults::{QueryResultsFormat, QueryResultsParser, QueryResultsReader}; + +fuzz_target!(|data: &[u8]| { + let parser = QueryResultsParser::from_format(QueryResultsFormat::Tsv); + if let Ok(QueryResultsReader::Solutions(solutions)) = parser.read_results(data) { + for _ in solutions {} + } +}); diff --git a/fuzz/fuzz_targets/sparql_results_xml.rs b/fuzz/fuzz_targets/sparql_results_xml.rs new file mode 100644 index 00000000..57c0c4cb --- /dev/null +++ b/fuzz/fuzz_targets/sparql_results_xml.rs @@ -0,0 +1,10 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; +use sparesults::{QueryResultsFormat, QueryResultsParser, QueryResultsReader}; + +fuzz_target!(|data: &[u8]| { + let parser = QueryResultsParser::from_format(QueryResultsFormat::Xml); + if let Ok(QueryResultsReader::Solutions(solutions)) = parser.read_results(data) { + for _ in solutions {} + } +}); diff --git a/fuzz/fuzz_targets/sparql_update.rs b/fuzz/fuzz_targets/sparql_update.rs new file mode 100644 index 00000000..252bf493 --- /dev/null +++ b/fuzz/fuzz_targets/sparql_update.rs @@ -0,0 +1,10 @@ +#![no_main] +use libfuzzer_sys::fuzz_target; +use spargebra::Update; +use std::str; + +fuzz_target!(|data: &[u8]| { + if let Ok(data) = str::from_utf8(data) { + Update::parse(data, None); + } +});