Nightly fuzzing on cnx01: text, uploads, the signed copy
.gitea/workflows/fuzz.yml runs cargo-fuzz (libFuzzer, nightly Rust) at 03:00 Chiang Mai time on runner02 on cnx01 (runs-on: cnx01; the label comes with cnx-network-clan PR #170), 10 minutes a target, under nice -n 19 (.gitea/scripts/fuzz.sh). Targets, bodies in src/fuzzing.rs: - text: passport zones and OCR output (whatever from_ocr returns must parse), positions, names, dates, Thai numbers, agreement texts and the contract diff. - upload: a file as files::sniff types it, through the pack's image and PDF code to a finished A4 page (pack::pdf::sides), EXIF orientation. - signed_copy: the drawn signature's PNG, or any text as the agreement, in the signed copy's PDF. fuzz/seeds/ holds small real files to start from (JPEG with JFIF and EXIF, PNG with pHYs, palette PNG, WebP lossy and lossless, A4 and landscape PDF, a drawn signature, zone, OCR, map links, Thai names). The grown corpus stays in the runner's cache; a crash fails the job and leaves its input as the artifact fuzz-findings, which goes into tests/fuzz_cases/<target>/ with the fix. tests/fuzz_cases.rs replays those and the seeds on every push, on stable. No sanitizer (safe Rust, about three times the inputs), debug assertions on, 10 s and 2 GB per input count as findings. DRAWING_LIMIT moved to agreements so the target uses the client page's limit. A local run of 60 s each in a Linux container: 635,522 / 9,763 / 4,089 inputs, peak 62 MB, nothing found.
This commit is contained in:
1 parent
7b5ec35e7c
commit
9b4d73c94b
38 files changed
+376
-16
No files matched your search
@@ -0,0 +1,53 @@
|
||||
//! Every input a fuzzer once broke a target with, replayed on every push
|
||||
//! (src/fuzzing.rs, fuzz/). A crash the nightly fuzzing finds goes into
|
||||
//! `tests/fuzz_cases/<target>/` with its fix, so it can never come back.
|
||||
|
||||
use std::fs;
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn the_inputs_the_fuzzers_found_stay_harmless() {
|
||||
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fuzz_cases");
|
||||
let mut tried = 0;
|
||||
for (name, target) in visa::fuzzing::TARGETS {
|
||||
let dir = root.join(name);
|
||||
let Ok(entries) = fs::read_dir(&dir) else {
|
||||
continue;
|
||||
};
|
||||
for e in entries {
|
||||
let path = e.unwrap().path();
|
||||
if path.extension().is_some_and(|x| x == "md") {
|
||||
continue;
|
||||
}
|
||||
let data = fs::read(&path).unwrap();
|
||||
let caught = std::panic::catch_unwind(|| target(&data));
|
||||
assert!(caught.is_ok(), "{name}: {} breaks it again", path.display());
|
||||
tried += 1;
|
||||
}
|
||||
}
|
||||
// the folder of every target exists, so a renamed one is noticed
|
||||
for (name, _) in visa::fuzzing::TARGETS {
|
||||
assert!(
|
||||
root.join(name).is_dir(),
|
||||
"tests/fuzz_cases/{name} is missing"
|
||||
);
|
||||
}
|
||||
eprintln!("{tried} fuzz cases replayed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_target_takes_its_seeds() {
|
||||
// the seeds the nightly run starts from (fuzz/seeds/) go through too
|
||||
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("fuzz/seeds");
|
||||
for (name, target) in visa::fuzzing::TARGETS {
|
||||
let dir = root.join(name);
|
||||
let files: Vec<_> = fs::read_dir(&dir)
|
||||
.unwrap_or_else(|_| panic!("fuzz/seeds/{name} is missing"))
|
||||
.map(|e| e.unwrap().path())
|
||||
.collect();
|
||||
assert!(!files.is_empty(), "fuzz/seeds/{name} is empty");
|
||||
for f in files {
|
||||
target(&fs::read(&f).unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
Inputs that once broke the fuzz target `signed_copy` (src/fuzzing.rs), replayed by
|
||||
`tests/fuzz_cases.rs`. Name each after what it broke.
|
||||
@@ -0,0 +1,2 @@
|
||||
Inputs that once broke the fuzz target `text` (src/fuzzing.rs), replayed by
|
||||
`tests/fuzz_cases.rs`. Name each after what it broke.
|
||||
@@ -0,0 +1,2 @@
|
||||
Inputs that once broke the fuzz target `upload` (src/fuzzing.rs), replayed by
|
||||
`tests/fuzz_cases.rs`. Name each after what it broke.
|
||||
@@ -10,6 +10,7 @@ mod common;
|
||||
mod companies;
|
||||
mod deadlines;
|
||||
mod documents;
|
||||
mod fuzz_cases;
|
||||
mod garage;
|
||||
mod legal;
|
||||
mod mrz_photo;
|
||||
|
||||
Reference in new issue
Block a user