Adds fuzzing to Oxigraph parsers

pull/190/head
Tpt 3 years ago
parent fc26fa87a5
commit 8c03e418a7
  1. 3
      fuzz/.gitignore
  2. 36
      fuzz/Cargo.toml
  3. 10
      fuzz/fuzz_targets/sparql_query.rs
  4. 15
      fuzz/fuzz_targets/sparql_results_json.rs
  5. 10
      fuzz/fuzz_targets/sparql_results_tsv.rs
  6. 10
      fuzz/fuzz_targets/sparql_results_xml.rs
  7. 10
      fuzz/fuzz_targets/sparql_update.rs

3
fuzz/.gitignore vendored

@ -0,0 +1,3 @@
target
corpus
artifacts

@ -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"

@ -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);
}
});

@ -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;
}
}
}
});

@ -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 {}
}
});

@ -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 {}
}
});

@ -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);
}
});
Loading…
Cancel
Save