Files
optimclaw/fuzz/fuzz_targets/fuzz_safety_validator.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

24 lines
681 B
Rust

#![no_main]
use libfuzzer_sys::fuzz_target;
use std::sync::LazyLock;
use ironclaw::safety::Validator;
static VALIDATOR: LazyLock<Validator> = LazyLock::new(Validator::new);
fuzz_target!(|data: &[u8]| {
if let Ok(s) = std::str::from_utf8(data) {
// Exercise input validation
let result = VALIDATOR.validate(s);
// Invariant: empty input is always invalid
if s.is_empty() {
assert!(!result.is_valid);
}
// Exercise tool parameter validation with arbitrary JSON
if let Ok(value) = serde_json::from_str::<serde_json::Value>(s) {
let _ = VALIDATOR.validate_tool_params(&value);
}
}
});