test: add fuzz harnesses and regression seeds
This commit is contained in:
parent
ab9f54b22d
commit
d4a2967ac8
|
|
@ -23,3 +23,8 @@ target/
|
|||
|
||||
# Generated locally by rust_autobadges/Cargo Tarpaulin
|
||||
/tarpaulin-report.html
|
||||
|
||||
# cargo-fuzz runtime output
|
||||
/fuzz/artifacts/
|
||||
/fuzz/coverage/
|
||||
/fuzz/target/
|
||||
|
|
|
|||
|
|
@ -70,3 +70,11 @@ task-level commit discipline are in [AGENTS.md](../AGENTS.md).
|
|||
|
||||
Each completed milestone receives an immutable annotated `milestone-N` Git tag
|
||||
after its acceptance criteria and quality gates pass.
|
||||
|
||||
## Fuzzing
|
||||
|
||||
The standalone [`fuzz`](../fuzz/) package contains five `cargo-fuzz` targets and
|
||||
reviewed seeds for configuration merging, rule validation/compilation, UTF-8
|
||||
span conversion, replacement invariants, and hostile archive bytes. See its
|
||||
README for invocation. Fuzz artifacts remain ignored until a failure has been
|
||||
minimized and promoted to a normal regression test.
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,52 @@
|
|||
[package]
|
||||
name = "john-slop-fuzz"
|
||||
version = "0.0.0"
|
||||
publish = false
|
||||
edition = "2024"
|
||||
|
||||
[package.metadata]
|
||||
cargo-fuzz = true
|
||||
|
||||
[dependencies]
|
||||
john_slop = { path = "..", default-features = false }
|
||||
libfuzzer-sys = "0.4.13"
|
||||
tempfile = "3.27.0"
|
||||
toml = "1.1.6"
|
||||
|
||||
[[bin]]
|
||||
name = "config-merge"
|
||||
path = "fuzz_targets/config_merge.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "rule-loading"
|
||||
path = "fuzz_targets/rule_loading.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "utf8-span-mapping"
|
||||
path = "fuzz_targets/utf8_span_mapping.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "replacement-planning"
|
||||
path = "fuzz_targets/replacement_planning.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[[bin]]
|
||||
name = "archive-metadata"
|
||||
path = "fuzz_targets/archive_metadata.rs"
|
||||
test = false
|
||||
doc = false
|
||||
bench = false
|
||||
|
||||
[workspace]
|
||||
members = ["."]
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# Fuzzing
|
||||
|
||||
The five harnesses exercise configuration layering, complete rule loading,
|
||||
UTF-8-to-UTF-16 span conversion, replacement planning/application, and hostile
|
||||
ZIP bytes under deliberately small resource limits.
|
||||
|
||||
Install `cargo-fuzz` and run one target from the repository root:
|
||||
|
||||
```sh
|
||||
cargo install cargo-fuzz --locked
|
||||
cargo fuzz run config-merge
|
||||
cargo fuzz run rule-loading
|
||||
cargo fuzz run utf8-span-mapping
|
||||
cargo fuzz run replacement-planning
|
||||
cargo fuzz run archive-metadata
|
||||
```
|
||||
|
||||
Checked-in seeds cover a valid partial override, a complete rule catalog,
|
||||
multibyte/CRLF text, overlapping replacement opportunities, and malformed ZIP
|
||||
metadata. Crashes and minimized artifacts are local build output and must not be
|
||||
committed until converted into a reviewed regression test.
|
||||
|
|
@ -0,0 +1 @@
|
|||
PKtruncated-central-directory
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
[[rules]]
|
||||
id = "templated-filler"
|
||||
enabled = false
|
||||
|
|
@ -0,0 +1 @@
|
|||
one—two–three−four‐five
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
schema_version = 1
|
||||
replacements = []
|
||||
|
||||
[thresholds]
|
||||
low = 20
|
||||
medium = 50
|
||||
high = 75
|
||||
|
||||
[input]
|
||||
max_document_bytes = 1024
|
||||
max_archive_bytes = 2048
|
||||
max_expanded_bytes = 4096
|
||||
max_archive_entries = 4
|
||||
max_compression_ratio = 10
|
||||
max_walk_depth = 4
|
||||
|
||||
[[rules]]
|
||||
id = "seed-rule"
|
||||
category = "style"
|
||||
severity = "advice"
|
||||
matcher = "regex"
|
||||
pattern = "seed+"
|
||||
weight = 1.0
|
||||
message = "seed match"
|
||||
help = "review the seed"
|
||||
occurrence_cap = 1
|
||||
enabled = true
|
||||
|
||||
[rules.scope]
|
||||
content = ["prose"]
|
||||
extensions = ["txt"]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
alpha
|
||||
é😀é
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#![no_main]
|
||||
|
||||
use std::fs;
|
||||
|
||||
use john_slop::{Config, read_inputs};
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let Ok(directory) = tempfile::tempdir() else {
|
||||
return;
|
||||
};
|
||||
let path = directory.path().join("input.zip");
|
||||
if fs::write(&path, data).is_err() {
|
||||
return;
|
||||
}
|
||||
let mut config = Config::embedded();
|
||||
config.input.max_archive_bytes = 64 * 1024;
|
||||
config.input.max_expanded_bytes = 128 * 1024;
|
||||
config.input.max_document_bytes = 16 * 1024;
|
||||
config.input.max_archive_entries = 32;
|
||||
config.input.max_compression_ratio = 20;
|
||||
if let Ok(documents) = read_inputs(&config, &path) {
|
||||
for document in documents.take(33) {
|
||||
let _ = document;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#![no_main]
|
||||
|
||||
use std::fs;
|
||||
|
||||
use john_slop::{ConfigLoader, ConfigPaths};
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let Ok(directory) = tempfile::tempdir() else {
|
||||
return;
|
||||
};
|
||||
let explicit = directory.path().join("fuzz.toml");
|
||||
if fs::write(&explicit, data).is_err() {
|
||||
return;
|
||||
}
|
||||
let loader = ConfigLoader::from_paths(ConfigPaths {
|
||||
directory: directory.path().to_path_buf(),
|
||||
base: directory.path().join("absent-base.toml"),
|
||||
named: Some(directory.path().join("absent-named.toml")),
|
||||
explicit: Some(explicit),
|
||||
});
|
||||
let _ = loader.load();
|
||||
});
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
#![no_main]
|
||||
|
||||
use john_slop::{Config, apply_replacements, plan_replacements};
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let Ok(source) = std::str::from_utf8(data) else {
|
||||
return;
|
||||
};
|
||||
let config = Config::embedded();
|
||||
let edits = plan_replacements(&config, source);
|
||||
let Ok(formatted) = apply_replacements(source, &edits) else {
|
||||
return;
|
||||
};
|
||||
let second = plan_replacements(&config, &formatted);
|
||||
let _ = apply_replacements(&formatted, &second);
|
||||
});
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#![no_main]
|
||||
|
||||
use john_slop::{Config, Detector};
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let Ok(source) = std::str::from_utf8(data) else {
|
||||
return;
|
||||
};
|
||||
let Ok(config) = toml::from_str::<Config>(source) else {
|
||||
return;
|
||||
};
|
||||
if config.validate().is_ok() {
|
||||
let _ = Detector::new(&config);
|
||||
}
|
||||
});
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
#![no_main]
|
||||
|
||||
use john_slop::lsp::LineIndex;
|
||||
use libfuzzer_sys::fuzz_target;
|
||||
|
||||
fuzz_target!(|data: &[u8]| {
|
||||
let Ok(source) = std::str::from_utf8(data) else {
|
||||
return;
|
||||
};
|
||||
let index = LineIndex::new(source);
|
||||
for offset in 0..=source.len().saturating_add(1) {
|
||||
let _ = index.position(offset);
|
||||
}
|
||||
if !source.is_empty() {
|
||||
let midpoint = source.len() / 2;
|
||||
let _ = index.range(midpoint..source.len());
|
||||
let _ = index.range(source.len()..midpoint);
|
||||
}
|
||||
});
|
||||
2
tasks.md
2
tasks.md
|
|
@ -220,7 +220,7 @@ same config.
|
|||
rule/replacement and how merge-by-ID works.
|
||||
- [x] Add CI on the supported OS/MSRV matrix for formatting, Clippy, tests, docs,
|
||||
audit/deny checks, and fixture/golden consistency.
|
||||
- [ ] Add fuzz targets for TOML/config merging, regex/rule loading, UTF-8 span
|
||||
- [x] Add fuzz targets for TOML/config merging, regex/rule loading, UTF-8 span
|
||||
mapping, replacement planning, and malicious ZIP metadata. Seed them with
|
||||
regression fixtures.
|
||||
- [ ] Benchmark large files, many small files, rule scaling, and archive limits.
|
||||
|
|
|
|||
Loading…
Reference in New Issue