From 12054cc89902c47bcef9759c2bb5c6401af9bf42 Mon Sep 17 00:00:00 2001 From: "Sergey \"Shnatsel\" Davidoff" Date: Wed, 29 Jul 2020 15:40:12 +0200 Subject: [PATCH] Fuzz: drop workarounds for operations that may panic (#92) Fuzz: drop workarounds for operations that may panic now that rutenspitz compares panic behavior --- fuzz/Cargo.toml | 2 +- fuzz/src/bin/arrayish.rs | 34 +++++++--------------------------- fuzz/src/bin/tinyvec.rs | 30 +++--------------------------- 3 files changed, 11 insertions(+), 55 deletions(-) diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 346528a..b38aab3 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -7,7 +7,7 @@ publish = false [dependencies] tinyvec = { path = "..", features = ["alloc", "nightly_slice_partition_dedup"] } -rutenspitz = "0.2" +rutenspitz = "0.2.1" honggfuzz = "0.5.45" arbitrary = { version = "0.4.5", features = ["derive"] } better-panic = "0.2.0" diff --git a/fuzz/src/bin/arrayish.rs b/fuzz/src/bin/arrayish.rs index e04283e..0fa6791 100644 --- a/fuzz/src/bin/arrayish.rs +++ b/fuzz/src/bin/arrayish.rs @@ -2,7 +2,7 @@ use honggfuzz::fuzz; use std::{ fmt::Debug, iter::FromIterator, - ops::{Bound, RangeBounds}, + ops::RangeBounds, }; use rutenspitz::arbitrary_stateful_operations; @@ -47,37 +47,16 @@ arbitrary_stateful_operations! { pre { match self { - Self::insert { index, .. } | Self::split_off { at: index } if index > model.len() => { - // TODO: Should test that these identically panic - return; - } - Self::remove { index } | Self::swap_remove { index } if index >= model.len() => { - // TODO: Should test that these identically panic - return; - } + // We are comparing ArrayVec with a limited capacity against + // Vec to which you can push indefinitely. This is a behavior mismatch. + // To compensate we skip adding any elements if it would exceed capacity. Self::insert { .. } | Self::push { .. } if model.len() == CAPACITY => { return; } Self::resize { new_len, .. } if new_len > CAPACITY => { return; } - Self::drain { ref range } => { - // TODO: Should test that these identically panic - let start = match range.start_bound() { - Bound::Included(&n) => n, - Bound::Excluded(&n) => n + 1, - Bound::Unbounded => 0, - }; - let end = match range.end_bound() { - // If it's already usize::max, doesn't really matter about adding 1 - Bound::Included(&n) => n.checked_add(1).unwrap_or(n), - Bound::Excluded(&n) => n, - Bound::Unbounded => model.len(), - }; - if start > end || end > model.len() { - return; - } - } + _ => {} } } @@ -89,7 +68,7 @@ fn fuzz_cycle(data: &[u8]) -> Result<(), ()> { let mut ring = Unstructured::new(&data); let mut model = Vec::::default(); - let mut tested: ArrayVec<[u16; 32]> = ArrayVec::new(); + let mut tested: ArrayVec<[u16; CAPACITY]> = ArrayVec::new(); let mut _op_trace = String::new(); while let Ok(op) = @@ -97,6 +76,7 @@ fn fuzz_cycle(data: &[u8]) -> Result<(), ()> { { #[cfg(fuzzing_debug)] _op_trace.push_str(&format!("{}\n", op.to_string())); + // println!("Operations trace:\n{}", _op_trace); op.execute_and_compare(&mut model, &mut tested); } diff --git a/fuzz/src/bin/tinyvec.rs b/fuzz/src/bin/tinyvec.rs index c89fd8d..87040ea 100644 --- a/fuzz/src/bin/tinyvec.rs +++ b/fuzz/src/bin/tinyvec.rs @@ -2,7 +2,7 @@ use honggfuzz::fuzz; use std::{ fmt::Debug, iter::FromIterator, - ops::{Bound, RangeBounds}, + ops::RangeBounds, }; use rutenspitz::arbitrary_stateful_operations; @@ -47,35 +47,10 @@ arbitrary_stateful_operations! { pre { match self { - Self::insert { index, .. } | Self::split_off { at: index } if index > model.len() => { - // TODO: Should test that these identically panic - return; - } - Self::remove { index } | Self::swap_remove { index } if index >= model.len() => { - // TODO: Should test that these identically panic - return; - } // Arbitrary limit to avoid allocating too large a buffer Self::resize { new_len, .. } if new_len > 4 * CAPACITY => { return; } - Self::drain { ref range } => { - // TODO: Should test that these identically panic - let start = match range.start_bound() { - Bound::Included(&n) => n, - Bound::Excluded(&n) => n + 1, - Bound::Unbounded => 0, - }; - let end = match range.end_bound() { - // If it's already usize::max, doesn't really matter about adding 1 - Bound::Included(&n) => n.checked_add(1).unwrap_or(n), - Bound::Excluded(&n) => n, - Bound::Unbounded => model.len(), - }; - if start > end || end > model.len() { - return; - } - } _ => {} } } @@ -87,7 +62,7 @@ fn fuzz_cycle(data: &[u8]) -> Result<(), ()> { let mut ring = Unstructured::new(&data); let mut model = Vec::::default(); - let mut tested: TinyVec<[u16; 32]> = TinyVec::new(); + let mut tested: TinyVec<[u16; CAPACITY]> = TinyVec::new(); let mut _op_trace = String::new(); while let Ok(op) = @@ -95,6 +70,7 @@ fn fuzz_cycle(data: &[u8]) -> Result<(), ()> { { #[cfg(fuzzing_debug)] _op_trace.push_str(&format!("{}\n", op.to_string())); + // println!("Operations trace:\n{}", _op_trace); op.execute_and_compare(&mut model, &mut tested); }