Constellation, Spacedust, Slingshot, UFOs: atproto crates and services for microcosm

simpler fuzz targets take a lot longer to crash

+2
Cargo.lock
···
name = "ufos-fuzz"
version = "0.0.0"
dependencies = [
+
"bincode 2.0.1",
+
"cardinality-estimator",
"jetstream",
"libfuzzer-sys",
"tikv-jemallocator",
+18 -6
ufos/fuzz/Cargo.toml
···
[dependencies]
libfuzzer-sys = "0.4"
-
-
[dependencies.ufos]
-
path = ".."
-
-
[dependencies.jetstream]
-
path = "../../jetstream"
+
ufos = { path = ".." }
+
jetstream = { path = "../../jetstream" }
+
bincode = { version = "2.0.1", features = ["serde"] }
+
cardinality-estimator = { version = "1.0.2", features = ["with_serde"] }
[target.'cfg(not(target_env = "msvc"))'.dependencies]
tikv-jemallocator = "0.6.0"
···
test = false
doc = false
bench = false
+
+
[[bin]]
+
name = "estimated_dids_value"
+
path = "fuzz_targets/estimated_dids_value.rs"
+
test = false
+
doc = false
+
bench = false
+
+
[[bin]]
+
name = "cardinality_estimator"
+
path = "fuzz_targets/cardinality_estimator.rs"
+
test = false
+
doc = false
+
bench = false
+30
ufos/fuzz/fuzz_targets/cardinality_estimator.rs
···
+
#![no_main]
+
+
use jetstream::exports::Did;
+
use bincode::config::{Configuration, BigEndian, Fixint, Limit, standard};
+
use bincode::serde::decode_from_slice;
+
use cardinality_estimator::CardinalityEstimator;
+
use libfuzzer_sys::fuzz_target;
+
+
#[cfg(not(target_env = "msvc"))]
+
use tikv_jemallocator::Jemalloc;
+
+
#[cfg(not(target_env = "msvc"))]
+
#[global_allocator]
+
static GLOBAL: Jemalloc = Jemalloc;
+
+
type C = Configuration<BigEndian, Fixint, Limit<1048576>>;
+
static BINCODE_CONF: C =
+
standard()
+
.with_big_endian()
+
.with_fixed_int_encoding()
+
.with_limit::<1048576>();
+
+
fuzz_target!(|data: &[u8]| {
+
if let Ok((estimator, _n)) = decode_from_slice::<CardinalityEstimator<Did>, C>(
+
data,
+
BINCODE_CONF,
+
) {
+
estimator.estimate();
+
}
+
});
+24
ufos/fuzz/fuzz_targets/estimated_dids_value.rs
···
+
#![no_main]
+
+
// use jetstream::exports::Did;
+
use ufos::db_types::DbBytes;
+
use ufos::store_types::EstimatedDidsValue;
+
use libfuzzer_sys::fuzz_target;
+
+
#[cfg(not(target_env = "msvc"))]
+
use tikv_jemallocator::Jemalloc;
+
+
#[cfg(not(target_env = "msvc"))]
+
#[global_allocator]
+
static GLOBAL: Jemalloc = Jemalloc;
+
+
fuzz_target!(|data: &[u8]| {
+
if let Ok((counts_value, n)) = EstimatedDidsValue::from_db_bytes(data) {
+
assert!(n <= data.len());
+
let serialized = counts_value.to_db_bytes().unwrap();
+
assert_eq!(serialized.len(), n);
+
let (and_back, n_again) = EstimatedDidsValue::from_db_bytes(&serialized).unwrap();
+
assert_eq!(n_again, n);
+
assert_eq!(and_back.0.estimate(), counts_value.0.estimate());
+
}
+
});