Skip to content

Commit

Permalink
add libafl compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
addisoncrump committed Jun 6, 2023
1 parent a730f92 commit 6c2b158
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
14 changes: 12 additions & 2 deletions fuzz/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ publish = false
edition = "2021"

[features]
default = ["libfuzzer"]
full-idempotency = []
libafl = ["libafl_libfuzzer"]
libfuzzer = ["libfuzzer-sys/link_libfuzzer"]

[package.metadata]
cargo-fuzz = true

[dependencies]
arbitrary = { version = "1.3.0", features = ["derive"] }
libfuzzer-sys = { version = "0.4.1" }
libafl_libfuzzer = { git = "https://github.com/AFLplusplus/LibAFL.git", branch = "libfuzzer", optional = true }
libfuzzer-sys = { git = "https://github.com/rust-fuzz/libfuzzer", default-features = false }
ruff = { path = "../crates/ruff" }
ruff_python_ast = { path = "../crates/ruff_python_ast" }
ruff_python_formatter = { path = "../crates/ruff_python_formatter" }
Expand Down
8 changes: 8 additions & 0 deletions fuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@ This fuzz harness checks that fixes applied by Ruff do not introduce new errors
[`ruff::test::test_snippet`](../crates/ruff/src/test.rs) testing utility.
It currently is only configured to use default settings, but may be extended in future versions to
test non-default linter settings.

## Experimental settings

You can optionally use `--no-default-features --features libafl` to use the libafl fuzzer instead of
libfuzzer.
This fuzzer has experimental support, but can vastly improve fuzzer performance.
If you are not already familiar with [LibAFL](https://github.com/AFLplusplus/LibAFL), this mode is
not currently recommended.
3 changes: 3 additions & 0 deletions fuzz/fuzz_targets/ruff_fix_validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#![no_main]

#[cfg(feature = "libafl")]
extern crate libafl_libfuzzer;

use libfuzzer_sys::{fuzz_target, Corpus};
use ruff::settings::Settings;
use std::sync::OnceLock;
Expand Down
3 changes: 3 additions & 0 deletions fuzz/fuzz_targets/ruff_parse_idempotency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#![no_main]

#[cfg(feature = "libafl")]
extern crate libafl_libfuzzer;

use libfuzzer_sys::{fuzz_target, Corpus};
use ruff_python_ast::source_code::round_trip;
use similar::TextDiff;
Expand Down
3 changes: 3 additions & 0 deletions fuzz/fuzz_targets/ruff_parse_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

#![no_main]

#[cfg(feature = "libafl")]
extern crate libafl_libfuzzer;

use libfuzzer_sys::{fuzz_target, Corpus};
use ruff_python_ast::source_code::round_trip;

Expand Down

0 comments on commit 6c2b158

Please sign in to comment.