fuzz: Add fuzz for askama_parser

This commit is contained in:
manunio 2023-09-11 18:21:59 +05:30 committed by Dirkjan Ochtman
parent 2e8e42af45
commit 8f3140a33f
4 changed files with 58 additions and 0 deletions

4
askama_parser/fuzz/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
target
corpus
artifacts
coverage

View File

@ -0,0 +1,27 @@
[package]
name = "askama_parser-fuzz"
version = "0.0.0"
publish = false
edition = "2021"
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.4"
[dependencies.askama_parser]
path = ".."
# Prevent this from interfering with workspaces
[workspace]
members = ["."]
[profile.release]
debug = 1
[[bin]]
name = "fuzz_parser"
path = "fuzz_targets/fuzz_parser.rs"
test = false
doc = false

View File

@ -0,0 +1,14 @@
# Fuzzing
Install `cargo-fuzz`:
```sh
cargo install -f cargo-fuzz
```
Run any available target where `$target` is the name of the target.
```sh
cargo fuzz list # get list of targets
cargo +nightly fuzz run $target
```

View File

@ -0,0 +1,13 @@
#![no_main]
use askama_parser::*;
use libfuzzer_sys::fuzz_target;
use std::str;
fuzz_target!(|data: &[u8]| {
// fuzzed code goes here
if data.len() < 500 {
if let Ok(data) = str::from_utf8(data) {
if let Ok(_) = Ast::from_str(data, &Syntax::default()) {}
}
}
});