Skip to content

Commit 9f99583

Browse files
authored
Don't try to fuzz unsupported compare on struct dtype (#2671)
1 parent 1da651f commit 9f99583

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

fuzz/fuzz_targets/array_ops.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ fuzz_target!(|fuzz_action: FuzzArrayAction| -> Corpus {
2222
for (i, (action, expected)) in actions.into_iter().enumerate() {
2323
match action {
2424
Action::Compress => {
25-
let compressed_array = BtrBlocksCompressor
25+
current_array = BtrBlocksCompressor
2626
.compress(current_array.to_canonical().vortex_unwrap().as_ref())
2727
.vortex_unwrap();
28-
assert_array_eq(&expected.array(), &compressed_array, i);
29-
current_array = compressed_array;
28+
assert_array_eq(&expected.array(), &current_array, i);
3029
}
3130
Action::Slice(range) => {
3231
current_array = slice(&current_array, range.start, range.end).vortex_unwrap();

fuzz/src/lib.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ use libfuzzer_sys::arbitrary::Error::EmptyChoose;
1313
use libfuzzer_sys::arbitrary::{Arbitrary, Result, Unstructured};
1414
pub use sort::sort_canonical_array;
1515
use vortex_array::aliases::hash_set::HashSet;
16-
use vortex_array::arrays::ListEncoding;
1716
use vortex_array::arrays::arbitrary::ArbitraryArray;
1817
use vortex_array::compute::{Operator, SearchResult, SearchSortedSide, scalar_at};
19-
use vortex_array::vtable::EncodingVTable;
20-
use vortex_array::{Array, ArrayRef, ArrayVisitorExt, EncodingId, IntoArray};
18+
use vortex_array::{Array, ArrayRef, IntoArray};
2119
use vortex_btrblocks::BtrBlocksCompressor;
2220
use vortex_buffer::Buffer;
21+
use vortex_dtype::DType;
2322
use vortex_error::{VortexUnwrap, vortex_panic};
2423
use vortex_mask::Mask;
2524
use vortex_scalar::Scalar;
@@ -74,7 +73,10 @@ impl<'a> Arbitrary<'a> for FuzzArrayAction {
7473
let array = ArbitraryArray::arbitrary(u)?.0;
7574
let mut current_array = array.to_array();
7675

77-
let valid_actions = actions_for_array(&current_array);
76+
let mut valid_actions = actions_for_dtype(current_array.dtype())
77+
.into_iter()
78+
.collect::<Vec<_>>();
79+
valid_actions.sort_unstable();
7880

7981
let mut actions = Vec::new();
8082
let action_count = u.int_in_range(1..=4)?;
@@ -201,21 +203,18 @@ fn random_value_from_list(u: &mut Unstructured<'_>, vec: &[usize]) -> Result<usi
201203

202204
const ALL_ACTIONS: RangeInclusive<usize> = 0..=5;
203205

204-
fn actions_for_encoding(encoding_id: EncodingId) -> HashSet<usize> {
205-
if ListEncoding.id() == encoding_id {
206+
fn actions_for_dtype(dtype: &DType) -> HashSet<usize> {
207+
match dtype {
208+
// All but compare
209+
DType::Struct(sdt, _) => sdt
210+
.fields()
211+
.map(|child| actions_for_dtype(&child))
212+
.fold((0..=4).collect(), |acc, actions| {
213+
acc.intersection(&actions).copied().collect()
214+
}),
215+
// Once we support more list operations also recurse here on child dtype
206216
// compress, slice
207-
vec![0, 1].into_iter().collect()
208-
} else {
209-
ALL_ACTIONS.collect()
217+
DType::List(..) => [0, 1].into_iter().collect(),
218+
_ => ALL_ACTIONS.collect(),
210219
}
211220
}
212-
213-
fn actions_for_array(array: &dyn Array) -> Vec<usize> {
214-
array
215-
.depth_first_traversal()
216-
.map(|child| actions_for_encoding(child.encoding()))
217-
.fold(ALL_ACTIONS.collect::<Vec<_>>(), |mut acc, actions| {
218-
acc.retain(|a| actions.contains(a));
219-
acc
220-
})
221-
}

0 commit comments

Comments
 (0)