cargo mutants: missed mutants in vortex-fuzz

Open
#12,630 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
testing

Research direction

Start by reviewing the listed surviving mutants in fuzz/fuzz_targets/file_io.rs and fuzz/corruption.rs, then run the corresponding cargo mutants commands included in the issue. Add or adjust fuzz tests so the relevant behavior is exercised and these mutants are caught. Done when the affected mutations no longer survive the fuzz test suite.

Written by the indexing model from the issue text.

Description

The nightly run at fdb9507c04e2939724aa39c298653a8ea3fd3b49 found 7 mutants in vortex-fuzz that survive the tests. They are in code that changed during the last day.

Artifacts:

fuzz/fuzz_targets/file_io.rs:93:9

replace FileRoundTrip::check -> bool with true

--- fuzz/fuzz_targets/file_io.rs
+++ replace FileRoundTrip::check -> bool with true
@@ -85,106 +85,17 @@
         }
         Ok(Self::File(u.arbitrary()?))
     }
 }
 
 impl FileRoundTrip {
     /// Writes, reopens, and scans the file. Returns false for unsupported schemas.
     fn check(self) -> bool {
-        let (array_data, split_at, projection_expr, filter_expr, write_options) = match self {
-            Self::File(action) => (
-                action.array,
-                None,
-                action.projection_expr,
-                action.filter_expr,
-                action.write_settings.write_options(),
-            ),
-            Self::Variant { array, split_at } => {
-                (array, split_at, None, None, SESSION.write_options())
-            }
-        };
-        if has_duplicate_field_names(array_data.dtype()) {
-            return false;
-        }
-
-        let mut ctx = SESSION.create_execution_ctx();
-        let expected_array = if filter_expr.is_none() && projection_expr.is_none() {
-            array_data.clone()
-        } else {
-            let bool_mask = array_data
-                .clone()
-                .apply(&filter_expr.clone().unwrap_or_else(|| lit(true)))
-                .vortex_expect("filter expression evaluation should succeed in fuzz test");
-            let bool_mask_bool = bool_mask
-                .execute::<BoolArray>(&mut ctx)
-                .vortex_expect("execute bool");
-            let mask = bool_mask_bool
-                .to_mask_fill_null_false(&mut ctx)
-                .vortex_expect("fill nulls of the filter mask");
-            let filtered = array_data
-                .filter(mask)
-                .vortex_expect("filter operation should succeed in fuzz test");
-            filtered
-                .apply(&projection_expr.clone().unwrap_or_else(root))
-                .vortex_expect("projection expression evaluation should succeed in fuzz test")
-        };
-
-        let input = if let Some(split) = split_at {
-            let first = array_data.slice(0..split).vortex_expect("valid split");
-            let second = array_data
-                .slice(split..array_data.len())
-                .vortex_expect("valid split");
-            ChunkedArray::from_iter([first, second]).into_array()
-        } else {
-            array_data
-        };
-
-        let mut full_buff = Vec::new();
-        let _footer = write_options
-            .blocking(&*RUNTIME)
-            .write(&mut full_buff, input.to_array_iterator())
-            .vortex_expect("file write should succeed in fuzz test");
-
-        let file = SESSION
-            .open_options()
-            .open_buffer(full_buff)
-            .vortex_expect("open_buffer should succeed in fuzz test");
-        let projection = projection_expr
-            .unwrap_or_else(root)
-            .bind(file.dtype())
-            .and_then(|expr| expr.optimize_recursive())
-            .vortex_expect("projection should bind in fuzz test");
-        let filter = filter_expr
-            .map(|filter| {
-                filter
-                    .bind(file.dtype())
-                    .and_then(|expr| expr.optimize_recursive())
-            })
-            .transpose()
-            .vortex_expect("filter should bind in fuzz test");
-        let mut output = file
-            .scan()
-            .vortex_expect("scan should succeed in fuzz test")
-            .with_projection(projection)
-            .with_some_filter(filter)
-            .into_array_iter(&*RUNTIME)
-            .vortex_expect("into_array_iter should succeed in fuzz test")
-            .try_collect::<_, Vec<_>, _>()
-            .vortex_expect("collect should succeed in fuzz test");
-
-        let output_array = match output.len() {
-            0 => Canonical::empty(expected_array.dtype()).into_array(),
-            1 => output.pop().vortex_expect("one output"),
-            _ => ChunkedArray::from_iter(output).into_array(),
-        };
-
-        assert_arrays_eq!(output_array, expected_array, &mut ctx);
-
-        true
+        true /* ~ changed by cargo-mutants ~ */
     }
 }
 
 fuzz_target!(|fuzz: FileRoundTrip| -> Corpus {
     if fuzz.check() {
         Corpus::Keep
     } else {
         Corpus::Reject
cargo mutants -f fuzz/fuzz_targets/file_io.rs -F ':93:9:'
fuzz/corruption.rs:210:5

replace run_prepared_corruption with ()

--- fuzz/corruption.rs
+++ replace run_prepared_corruption with ()
@@ -202,22 +202,17 @@
 });
 
 pub fn run_prepared_corruption(data: &[u8], read: ReadCorrupted) {
     // This is a hack to unblock fuzzer. Inputs like this, including empty
     // data, make fuzzer immediately crash with an OOM which is a genuine bug
     // but doesn't help discover other errors. Remove when this is fixed:
     // https://github.com/vortex-data/vortex/issues/12173
     // https://github.com/vortex-data/vortex/issues/12244
-    if data.len() <= size_of::<u16>() {
-        return;
-    }
-    let (selector, seed): (u16, u64) = Unstructured::new(data).arbitrary().unwrap_or_default();
-    let (file, targets) = &FILES[usize::from(selector) % FILES.len()];
-    read_corruption_sets(file, targets, seed, read);
+    () /* ~ changed by cargo-mutants ~ */
 }
 
 fn read_corruption_sets(file: &[u8], targets: &Targets, seed: u64, read: ReadCorrupted) {
     report_on_panic(|| {
         for (position, corruption) in CURRENT_SET.get().into_iter().flatten() {
             eprintln!("corruption {position} {corruption:?}");
         }
     });
cargo mutants -f fuzz/corruption.rs -F ':210:5:'
fuzz/corruption.rs:210:19

replace <= with > in run_prepared_corruption

--- fuzz/corruption.rs
+++ replace <= with > in run_prepared_corruption
@@ -202,17 +202,17 @@
 });
 
 pub fn run_prepared_corruption(data: &[u8], read: ReadCorrupted) {
     // This is a hack to unblock fuzzer. Inputs like this, including empty
     // data, make fuzzer immediately crash with an OOM which is a genuine bug
     // but doesn't help discover other errors. Remove when this is fixed:
     // https://github.com/vortex-data/vortex/issues/12173
     // https://github.com/vortex-data/vortex/issues/12244
-    if data.len() <= size_of::<u16>() {
+    if data.len() > /* ~ changed by cargo-mutants ~ */ size_of::<u16>() {
         return;
     }
     let (selector, seed): (u16, u64) = Unstructured::new(data).arbitrary().unwrap_or_default();
     let (file, targets) = &FILES[usize::from(selector) % FILES.len()];
     read_corruption_sets(file, targets, seed, read);
 }
 
 fn read_corruption_sets(file: &[u8], targets: &Targets, seed: u64, read: ReadCorrupted) {
cargo mutants -f fuzz/corruption.rs -F ':210:19:'
fuzz/corruption.rs:214:56

replace % with / in run_prepared_corruption

--- fuzz/corruption.rs
+++ replace % with / in run_prepared_corruption
@@ -206,17 +206,17 @@
     // data, make fuzzer immediately crash with an OOM which is a genuine bug
     // but doesn't help discover other errors. Remove when this is fixed:
     // https://github.com/vortex-data/vortex/issues/12173
     // https://github.com/vortex-data/vortex/issues/12244
     if data.len() <= size_of::<u16>() {
         return;
     }
     let (selector, seed): (u16, u64) = Unstructured::new(data).arbitrary().unwrap_or_default();
-    let (file, targets) = &FILES[usize::from(selector) % FILES.len()];
+    let (file, targets) = &FILES[usize::from(selector) / /* ~ changed by cargo-mutants ~ */ FILES.len()];
     read_corruption_sets(file, targets, seed, read);
 }
 
 fn read_corruption_sets(file: &[u8], targets: &Targets, seed: u64, read: ReadCorrupted) {
     report_on_panic(|| {
         for (position, corruption) in CURRENT_SET.get().into_iter().flatten() {
             eprintln!("corruption {position} {corruption:?}");
         }
cargo mutants -f fuzz/corruption.rs -F ':214:56:'
fuzz/corruption.rs:214:56

replace % with + in run_prepared_corruption

--- fuzz/corruption.rs
+++ replace % with + in run_prepared_corruption
@@ -206,17 +206,17 @@
     // data, make fuzzer immediately crash with an OOM which is a genuine bug
     // but doesn't help discover other errors. Remove when this is fixed:
     // https://github.com/vortex-data/vortex/issues/12173
     // https://github.com/vortex-data/vortex/issues/12244
     if data.len() <= size_of::<u16>() {
         return;
     }
     let (selector, seed): (u16, u64) = Unstructured::new(data).arbitrary().unwrap_or_default();
-    let (file, targets) = &FILES[usize::from(selector) % FILES.len()];
+    let (file, targets) = &FILES[usize::from(selector) + /* ~ changed by cargo-mutants ~ */ FILES.len()];
     read_corruption_sets(file, targets, seed, read);
 }
 
 fn read_corruption_sets(file: &[u8], targets: &Targets, seed: u64, read: ReadCorrupted) {
     report_on_panic(|| {
         for (position, corruption) in CURRENT_SET.get().into_iter().flatten() {
             eprintln!("corruption {position} {corruption:?}");
         }
cargo mutants -f fuzz/corruption.rs -F ':214:56:'
fuzz/corruption.rs:219:5

replace read_corruption_sets with ()

--- fuzz/corruption.rs
+++ replace read_corruption_sets with ()
@@ -211,44 +211,17 @@
         return;
     }
     let (selector, seed): (u16, u64) = Unstructured::new(data).arbitrary().unwrap_or_default();
     let (file, targets) = &FILES[usize::from(selector) % FILES.len()];
     read_corruption_sets(file, targets, seed, read);
 }
 
 fn read_corruption_sets(file: &[u8], targets: &Targets, seed: u64, read: ReadCorrupted) {
-    report_on_panic(|| {
-        for (position, corruption) in CURRENT_SET.get().into_iter().flatten() {
-            eprintln!("corruption {position} {corruption:?}");
-        }
-    });
-
-    // Technically this approach makes fuzzer mutator useless as any seed
-    // change implies completely different corruptions. However, in this
-    // fuzzer we don't actually care about composing corruptions. We do care
-    // about speed. Seed + rng compared to a seed-only corruption solution
-    // finds roughly 3x more errors during same fuzzing time
-    let mut rng = Xoshiro256PlusPlus::seed_from_u64(seed);
-    let mut ctx = SESSION.create_execution_ctx();
-    for _ in 0..CORRUPTION_SETS {
-        let mut entropy = [0u8; SET_ENTROPY_BYTES];
-        rng.fill(&mut entropy);
-        let mut u = Unstructured::new(&entropy);
-        let mut corrupted = file.to_vec();
-        let mut applied = [None; MAX_CORRUPTIONS];
-        let len = u.int_in_range(1..=MAX_CORRUPTIONS).unwrap_or(1);
-        for slot in applied.iter_mut().take(len) {
-            let corruption = u.arbitrary().ok();
-            *slot = corruption.and_then(|corruption| targets.apply(&mut corrupted, corruption));
-        }
-        CURRENT_SET.set(applied);
-        read(&mut ctx, corrupted).ok();
-    }
-    CURRENT_SET.set([None; MAX_CORRUPTIONS]);
+    () /* ~ changed by cargo-mutants ~ */
 }
 
 fn postscript(file: &[u8]) -> Option<fb::Postscript<'_>> {
     let eof_start = file.len() - EOF_SIZE;
     let start = eof_start + VERSION_BYTES;
     let end = start + POSTSCRIPT_LEN_BYTES;
     let len_bytes: [u8; POSTSCRIPT_LEN_BYTES] = file.get(start..end)?.try_into().ok()?;
     let postscript_len = usize::from(u16::from_le_bytes(len_bytes));
cargo mutants -f fuzz/corruption.rs -F ':219:5:'
fuzz/fuzz_targets/file_io.rs:93:9

replace FileRoundTrip::check -> bool with false

--- fuzz/fuzz_targets/file_io.rs
+++ replace FileRoundTrip::check -> bool with false
@@ -85,106 +85,17 @@
         }
         Ok(Self::File(u.arbitrary()?))
     }
 }
 
 impl FileRoundTrip {
     /// Writes, reopens, and scans the file. Returns false for unsupported schemas.
     fn check(self) -> bool {
-        let (array_data, split_at, projection_expr, filter_expr, write_options) = match self {
-            Self::File(action) => (
-                action.array,
-                None,
-                action.projection_expr,
-                action.filter_expr,
-                action.write_settings.write_options(),
-            ),
-            Self::Variant { array, split_at } => {
-                (array, split_at, None, None, SESSION.write_options())
-            }
-        };
-        if has_duplicate_field_names(array_data.dtype()) {
-            return false;
-        }
-
-        let mut ctx = SESSION.create_execution_ctx();
-        let expected_array = if filter_expr.is_none() && projection_expr.is_none() {
-            array_data.clone()
-        } else {
-            let bool_mask = array_data
-                .clone()
-                .apply(&filter_expr.clone().unwrap_or_else(|| lit(true)))
-                .vortex_expect("filter expression evaluation should succeed in fuzz test");
-            let bool_mask_bool = bool_mask
-                .execute::<BoolArray>(&mut ctx)
-                .vortex_expect("execute bool");
-            let mask = bool_mask_bool
-                .to_mask_fill_null_false(&mut ctx)
-                .vortex_expect("fill nulls of the filter mask");
-            let filtered = array_data
-                .filter(mask)
-                .vortex_expect("filter operation should succeed in fuzz test");
-            filtered
-                .apply(&projection_expr.clone().unwrap_or_else(root))
-                .vortex_expect("projection expression evaluation should succeed in fuzz test")
-        };
-
-        let input = if let Some(split) = split_at {
-            let first = array_data.slice(0..split).vortex_expect("valid split");
-            let second = array_data
-                .slice(split..array_data.len())
-                .vortex_expect("valid split");
-            ChunkedArray::from_iter([first, second]).into_array()
-        } else {
-            array_data
-        };
-
-        let mut full_buff = Vec::new();
-        let _footer = write_options
-            .blocking(&*RUNTIME)
-            .write(&mut full_buff, input.to_array_iterator())
-            .vortex_expect("file write should succeed in fuzz test");
-
-        let file = SESSION
-            .open_options()
-            .open_buffer(full_buff)
-            .vortex_expect("open_buffer should succeed in fuzz test");
-        let projection = projection_expr
-            .unwrap_or_else(root)
-            .bind(file.dtype())
-            .and_then(|expr| expr.optimize_recursive())
-            .vortex_expect("projection should bind in fuzz test");
-        let filter = filter_expr
-            .map(|filter| {
-                filter
-                    .bind(file.dtype())
-                    .and_then(|expr| expr.optimize_recursive())
-            })
-            .transpose()
-            .vortex_expect("filter should bind in fuzz test");
-        let mut output = file
-            .scan()
-            .vortex_expect("scan should succeed in fuzz test")
-            .with_projection(projection)
-            .with_some_filter(filter)
-            .into_array_iter(&*RUNTIME)
-            .vortex_expect("into_array_iter should succeed in fuzz test")
-            .try_collect::<_, Vec<_>, _>()
-            .vortex_expect("collect should succeed in fuzz test");
-
-        let output_array = match output.len() {
-            0 => Canonical::empty(expected_array.dtype()).into_array(),
-            1 => output.pop().vortex_expect("one output"),
-            _ => ChunkedArray::from_iter(output).into_array(),
-        };
-
-        assert_arrays_eq!(output_array, expected_array, &mut ctx);
-
-        true
+        false /* ~ changed by cargo-mutants ~ */
     }
 }
 
 fuzz_target!(|fuzz: FileRoundTrip| -> Corpus {
     if fuzz.check() {
         Corpus::Keep
     } else {
         Corpus::Reject
cargo mutants -f fuzz/fuzz_targets/file_io.rs -F ':93:9:'
Dominant language
Rust
Stars
3.2k
Forks
239
Avg merge
1d 4h
Merged PRs (30d)
684

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vortex-data/vortex

All issues in vortex-data/vortex

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.