Add cargo-fuzz targets: header parsing, URI parsing for OSS-Fuzz

This commit is contained in:
can olgun 2026-06-13 23:25:50 +03:00
parent a1b4165c34
commit 2ba30e5bef
3 changed files with 55 additions and 0 deletions

27
fuzz/Cargo.toml Normal file
View File

@ -0,0 +1,27 @@
[package]
name = "actix-fuzz"
version = "0.0.0"
edition = "2021"
publish = false
[package.metadata]
cargo-fuzz = true
[dependencies]
libfuzzer-sys = "0.4"
actix-http = { path = "../actix-http" }
http = "1"
bytes = "1"
tokio = { version = "1", features = ["rt", "macros"] }
[[bin]]
name = "fuzz_header_parse"
path = "fuzz_targets/fuzz_header_parse.rs"
test = false
doc = false
[[bin]]
name = "fuzz_uri_parse"
path = "fuzz_targets/fuzz_uri_parse.rs"
test = false
doc = false

View File

@ -0,0 +1,20 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use actix_http::header::HeaderMap;
use http::header::{HeaderName, HeaderValue};
fuzz_target!(|data: &[u8]| {
if data.len() < 2 { return; }
let split = data[0] as usize % data.len().min(64);
let (name, value) = if split < data.len() {
(&data[..split.min(data.len())], &data[split.min(data.len())..])
} else {
(data, &[] as &[u8])
};
let _ = HeaderName::from_bytes(name).map(|n| {
let _ = HeaderValue::from_bytes(value).map(|v| {
let mut map = HeaderMap::new();
map.insert(n, v);
});
});
});

View File

@ -0,0 +1,8 @@
#![no_main]
use libfuzzer_sys::fuzz_target;
use bytes::Bytes;
use http::Uri;
fuzz_target!(|data: &[u8]| {
let _ = Uri::from_maybe_shared(Bytes::copy_from_slice(data));
});