Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fuzz: Add fuzz for askama_parser #862

Merged
merged 1 commit into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions askama_parser/fuzz/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
target
corpus
artifacts
coverage
27 changes: 27 additions & 0 deletions askama_parser/fuzz/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions askama_parser/fuzz/README.md
Original file line number Diff line number Diff line change
@@ -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
```
13 changes: 13 additions & 0 deletions askama_parser/fuzz/fuzz_targets/fuzz_parser.rs
Original file line number Diff line number Diff line change
@@ -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 {
djc marked this conversation as resolved.
Show resolved Hide resolved
if let Ok(data) = str::from_utf8(data) {
if let Ok(_) = Ast::from_str(data, &Syntax::default()) {}
}
}
});
Loading