Files
optimclaw/fuzz/fuzz_targets/fuzz_leak_detector.rs
[email protected]andClaude Opus 4.6 97cbe38949 fix(fuzz): address PR review — LazyLock for expensive constructors, fix assertions and docs
- Use std::sync::LazyLock to construct Sanitizer, Validator, and LeakDetector
  once instead of on every fuzz iteration (they compile regex/Aho-Corasick)
- Remove fuzz_config_env assertion that panics on null-byte-only input
- Remove no-op length check with misleading comment in fuzz_config_env
- Update fuzz_config_env description in README to match actual behavior

Co-Authored-By: Claude Opus 4.6 <[email protected]>
2026-03-10 11:15:56 -07:00

26 lines
722 B
Rust

#![no_main]
use libfuzzer_sys::fuzz_target;
use std::sync::LazyLock;
use ironclaw::safety::LeakDetector;
static DETECTOR: LazyLock<LeakDetector> = LazyLock::new(LeakDetector::new);
fuzz_target!(|data: &[u8]| {
if let Ok(s) = std::str::from_utf8(data) {
// Exercise scan path
let result = DETECTOR.scan(s);
// Invariant: if should_block, there must be matches
if result.should_block {
assert!(!result.matches.is_empty());
}
// Invariant: match locations must be valid
for m in &result.matches {
assert!(m.location.end <= s.len());
}
// Exercise scan_and_clean path
let _ = DETECTOR.scan_and_clean(s);
}
});