diff --git a/.github/workflows/fuzzing.yml b/.github/workflows/fuzzing.yml index 9093cc6c..f5b32b1b 100644 --- a/.github/workflows/fuzzing.yml +++ b/.github/workflows/fuzzing.yml @@ -23,10 +23,7 @@ jobs: - name: fuzz run: | cargo install cargo-fuzz - set -e - for i in {1..6}; do - cargo fuzz run main -- -max_total_time=300 -rss_limit_mb=4096 - done + cargo fuzz run main -- -max_total_time=1800 -rss_limit_mb=4096 - name: minimize corpus if: always() run: cargo fuzz cmin main diff --git a/fuzz/fuzz_targets/main.rs b/fuzz/fuzz_targets/main.rs index 3eec3ecb..42a1268a 100644 --- a/fuzz/fuzz_targets/main.rs +++ b/fuzz/fuzz_targets/main.rs @@ -4,6 +4,9 @@ use {arbitrary::Arbitrary, libfuzzer_sys::fuzz_target, smallvec::SmallVec, std::fmt::Debug}; +// Upper bound on the harness's test vectors's capacity. +const MAX_CAP: usize = 1024; + /// A generic wrapper that bounds data generated via `arbitrary`. /// Default cap is 255. #[derive(Debug, Clone)] @@ -47,8 +50,8 @@ enum Op { New, WithCapacity(Bounded), FromVec, - FromSlice(Bounded>), - Push(usize), + FromSlice(Bounded>), + Push(u64), Pop, Grow(Bounded), Reserve(Bounded), @@ -58,12 +61,12 @@ enum Op { SwapRemove, Clear, Remove, - Insert(usize), + Insert(u64), Drain, RetainEven, Dedup, - ExtendFromSlice(Bounded>), - Resize(Bounded, usize), + ExtendFromSlice(Bounded>), + Resize(Bounded, u64), } /// Helper to assert equivalence of all structural invariants of `SmallVec` @@ -135,12 +138,12 @@ fn test_with_inline_cap( u: &mut arbitrary::Unstructured, ops: &[Op], ) -> arbitrary::Result<()> { - // We let `T` be `usize` instead of `u8` because, albeit less efficient, + // We let `T` be `u64` instead of `u8` because, albeit less efficient, // this incurs potential memory misalignment which should be properly // handled by the library. - let mut small_vec = SmallVec::<[usize; N]>::new(); - let mut std_vec = Vec::::new(); + let mut small_vec = SmallVec::<[u64; N]>::new(); + let mut std_vec = Vec::::new(); for op in ops { match op { @@ -251,6 +254,13 @@ fn test_with_inline_cap( } } + if small_vec.capacity() > MAX_CAP { + small_vec.truncate(MAX_CAP); + std_vec.truncate(MAX_CAP); + small_vec.shrink_to_fit(); + std_vec.shrink_to_fit(); + } + assert_invariants(&mut small_vec, &mut std_vec); } @@ -261,7 +271,7 @@ fn run_test(mut u: arbitrary::Unstructured) -> arbitrary::Result<()> { let ops = Vec::::arbitrary(&mut u)?; let dynamic_entropy = u.take_rest(); - let run_test = |test_func: fn(&mut arbitrary::Unstructured, &[Op]) -> arbitrary::Result<()>| { + let run_test = |test_func: fn(&mut arbitrary::Unstructured, &[Op]) -> _| { test_func(&mut arbitrary::Unstructured::new(dynamic_entropy), &ops) };