Files
wickra/fuzz/fuzz_targets/tick_aggregator.rs
T
kingchenc 78c31d1bed E16: add a cargo-fuzz harness
The repository had no fuzzing setup despite several natural targets —
the CSV parser, the Binance envelope deserializer, and the stateful
indicator/aggregator update paths.

Add a fuzz/ cargo-fuzz crate (detached from the workspace via its own
[workspace] table and the parent's exclude) with four targets:

- csv_reader      — CandleReader over arbitrary bytes
- binance_envelope — RawWsEnvelope deserialization from arbitrary strings
- indicator_update — RSI/EMA streaming + batch over arbitrary f64 series
- tick_aggregator — TickAggregator over arbitrary tick triples

Each target asserts the no-panic contract: malformed input must surface
as an Err. fuzz/README.md documents running them (nightly + cargo-fuzz).
2026-05-22 16:44:19 +02:00

26 lines
851 B
Rust

#![no_main]
//! Fuzz the tick-to-candle aggregator with arbitrary `(price, volume,
//! timestamp)` triples.
//!
//! The aggregator must never panic — out-of-order ticks and volume overflow
//! have to surface as an `Err`, and `Timeframe::floor` must not overflow for
//! any `i64` timestamp.
use libfuzzer_sys::fuzz_target;
use wickra_core::Tick;
use wickra_data::aggregator::{TickAggregator, Timeframe};
fuzz_target!(|data: Vec<(f64, f64, i64)>| {
let mut agg = TickAggregator::new(Timeframe::new(60).unwrap()).with_gap_fill(true);
for (price, volume, ts) in data {
let Ok(tick) = Tick::new(price, volume, ts) else {
continue;
};
if agg.push(tick).is_err() {
// An out-of-order tick is a defined error; stop feeding this run.
break;
}
}
let _ = agg.flush();
});