Skip to content

Fuzzing Crash: VortexError in file_scan_expr_v2 #12552

Backlog

Description

@github-actions

Target crashed at vortex-array/src/validity.rs:480:cast_nullability:

Failed to compute validity mask:
  Cannot cast array with invalid values to non-nullable type.
Stack trace
stack backtrace:
   1: core::panicking::panic_fmt
             at /rustc/8eb778d04094d3af4b26580cab327e0413eb1e02/library/core/src/panicking.rs:80:14
   2: panic_display<vortex_error::VortexError>
             at /home/runner/.rustup/toolchains/nightly-2026-11-13-aarch64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:259:5
   3: result_expect_failed<vortex_error::VortexError>
             at ./vortex-error/src/lib.rs:553:9
   4: vortex_expect<vortex_mask::Mask, vortex_error::VortexError>
             at ./vortex-error/src/lib.rs:258:25
   5: to_mask_fill_null_false<vortex_array::array::typed::Array<vortex_array::arrays::bool::vtable::Bool>>
             at ./vortex-array/src/arrays/bool/array.rs:132:14
   6: execute
             at ./vortex-functions/src/case_when/mod.rs:271:39
   7: execute_step<vortex_functions::case_when::CaseWhen>
             at ./vortex-array/src/scalar_fn/vtable.rs:242:14
   8: execute_step<vortex_functions::case_when::CaseWhen>
             at ./vortex-array/src/scalar_fn/typed.rs:198:22
   9: execute_step
             at ./vortex-array/src/scalar_fn/erased.rs:164:16
  10: execute
             at ./vortex-array/src/arrays/scalar_fn/vtable/mod.rs:155:33
  11: execute_encoding<vortex_array::arrays::scalar_fn::vtable::ScalarFn>
             at ./vortex-array/src/array/mod.rs:271:5
  12: execute_encoding_unchecked
             at ./vortex-array/src/array/erased.rs:752:9
  13: execute_until<vortex_array::canonical::AnyCanonical>
             at ./vortex-array/src/executor/mod.rs:455:40
  14: execute
             at ./vortex-array/src/canonical.rs:597:28
  15: execute<vortex_array::canonical::Canonical>
             at ./vortex-array/src/executor/mod.rs:109:9
  16: execute
             at ./vortex-array/src/canonical.rs:806:21
  17: execute<vortex_array::canonical::RecursiveCanonical>
             at ./vortex-array/src/executor/mod.rs:109:9
  18: {closure#0}<vortex_io::runtime::current::CurrentThreadIterator<core::result::Result<vortex_array::array::erased::ArrayRef, vortex_error::VortexError>>, file_scan_expr_v2::_::__libfuzzer_sys_run::{closure_env#0}>
             at ./fuzz/scan_expr.rs:89:24
  19: run<vortex_io::runtime::current::CurrentThreadIterator<core::result::Result<vortex_array::array::erased::ArrayRef, vortex_error::VortexError>>, file_scan_expr_v2::_::__libfuzzer_sys_run::{closure_env#0}>
             at ./fuzz/scan_expr.rs:93:9
  20: run_file_scan_expr<vortex_io::runtime::current::CurrentThreadIterator<core::result::Result<vortex_array::array::erased::ArrayRef, vortex_error::VortexError>>, file_scan_expr_v2::_::__libfuzzer_sys_run::{closure_env#0}>
... (29 more frames truncated)

To reproduce, download the crash artifact to ~/Downloads and run these
commands from the repository root:

unzip ~/Downloads/file_scan_expr_v2-crash-artifacts.zip -d fuzz-artifacts
RUST_BACKTRACE=1 cargo +nightly fuzz run -D --sanitizer=none \
  file_scan_expr_v2 \
  fuzz-artifacts/file_scan_expr_v2/crash-71561a38e95bdbd69096c96b41e87ff3cda070c1 \
  -- -rss_limit_mb=0

Auto-created by fuzzing workflow

Activity

  1. added
    fuzzer
    bug
    on Dec 2, 2026
  2. github-actions commented on Dec 2, 2026

    @github-actions
    ContributorAuthor

    Seen 13 times

  3. github-actions commented on Dec 2, 2026

    @github-actions
    ContributorAuthor

    🤖 Fuzzer fix: ✅ succeeded

    The fix passed the fuzz-fix-review skill, and a draft pull request is open: #12560

    Run 46803941014, attempt 1 · started 2026-12-02T05:13:07Z · finished 2026-12-02T05:44:56Z

  4. vortex-claude commented on Dec 2, 2026

    @vortex-claude
    Contributor

    Root cause

    The crash comes from this projection:

    case_when_no_else(
      mask(is_not_null(root), cast(not_ilike(case_when(null, root, root), root), Bool NonNullable)),
      ...
    )
    

    The cast to non-nullable Bool is invalid for this input, because not_ilike yields nulls for null rows. That should be a normal VortexError. The error is not raised where the cast is built. Mask::execute_canonical attaches the mask child to the result as lazy Validity::Array without executing it. Lazy mask validity is deliberate: see the MaskReduce docs and the all_valid_input_attaches_lazy_mask test.

    vortex-array/src/scalar_fn/builtin/mask/mod.rs:198:

    fn execute_canonical(
        input: ArrayRef,
        mask_array: ArrayRef,
        ctx: &mut ExecutionCtx,
    ) -> VortexResult<ArrayRef> {
        let validity = child_to_validity(Some(&mask_array), Nullability::Nullable);
        let canonical = input.execute::<Canonical>(ctx)?;
        Ok(mask_validity_canonical(canonical, validity, ctx)?.into_array())
    }

    CASE WHEN then turns the condition into a mask. BoolArrayExt::to_mask_fill_null_false executes the lazy validity, the cast fails, and vortex_expect turns the error into a panic.

    Crash location, vortex-array/src/arrays/bool/array.rs:129 (before the fix):

    fn to_mask_fill_null_false(&self, ctx: &mut ExecutionCtx) -> Mask {
        let validity_mask = BoolArrayExt::validity(self)
            .execute_mask(self.len(), ctx)
            .vortex_expect("Failed to compute validity mask");
        ...
    }

    Validity::execute_mask already returns VortexResult, because executing lazy validity can fail. The bug is in the library: to_mask_fill_null_false assumed that execution could not fail.

    Fix

    to_mask_fill_null_false now returns VortexResult<Mask>. Its callers that run in library code pass the error on with ?: CaseWhen::execute, Zip::execute and Python PyArray::filter. The fuzz file_io target and the compute::conformance::mask helper keep vortex_expect, as test code.

    This changes the signature of the public BoolArrayExt trait, so the PR should carry changelog/break.

    /// Converts to a [`Mask`] that treats null values as `false`.
    ///
    /// # Errors
    ///
    /// Returns an error if the validity cannot be executed. Validity can be a lazy array, such as
    /// the mask child that `mask` attaches, and executing it can fail.
    fn to_mask_fill_null_false(&self, ctx: &mut ExecutionCtx) -> VortexResult<Mask> {
        let validity_mask = BoolArrayExt::validity(self).execute_mask(self.len(), ctx)?;
        let buffer = match validity_mask {
            Mask::AllTrue(_) => self.to_bit_buffer(),
            Mask::AllFalse(_) => return Ok(Mask::new_false(self.len())),
            Mask::Values(validity) => validity.bit_buffer() & self.to_bit_buffer(),
        };
        Ok(Mask::from_buffer(buffer))
    }

    Caller changes:

    // vortex-functions/src/case_when/mod.rs (CaseWhen::execute)
    let cond_mask = cond_bool.to_mask_fill_null_false(ctx)?;
    
    // vortex-functions/src/zip/mod.rs (Zip::execute)
    let mask = mask_array
        .execute::<BoolArray>(ctx)?
        .to_mask_fill_null_false(ctx)?;
    
    // vortex-python/src/arrays/mod.rs (PyArray::filter)
    let mask = mask
        .execute::<BoolArray>(&mut ctx)?
        .to_mask_fill_null_false(&mut ctx)?;

    I rejected the other option, executing the mask child eagerly in Mask::execute_canonical. It would undo the documented lazy-mask design, and the error would still panic for any other lazy validity that fails.

    Regression test

    The test is in vortex-functions/src/case_when/tests.rs. It goes through the same path as the crash: expression application, then CASE WHEN execution, then the lazy mask validity.

    /// `mask` attaches its mask child as lazy validity, so a mask that fails to execute (here a
    /// cast of nulls to non-nullable) only fails once CASE WHEN reads the condition's validity.
    /// That failure must surface as an error rather than a panic.
    #[test]
    fn condition_with_failing_lazy_validity_returns_error() -> VortexResult<()> {
        let mut ctx = SESSION.create_execution_ctx();
        let input = BoolArray::from_iter([Some(true), None, Some(false)]).into_array();
        let condition = mask(
            is_not_null(root()),
            cast(root(), DType::Bool(Nullability::NonNullable)),
        );
        let expr = case_when_no_else(condition, lit(1i32));
    
        let Err(error) = input.apply(&expr)?.execute::<Canonical>(&mut ctx) else {
            panic!("casting a null mask to non-nullable must fail");
        };
        assert!(
            error
                .to_string()
                .contains("Cannot cast array with invalid values to non-nullable type"),
            "{error}"
        );
        Ok(())
    }

    Commands run

    Command Result
    cargo test -p vortex-functions condition_with_failing_lazy_validity before the fix Failed: panicked with Failed to compute validity mask: Cannot cast array with invalid values to non-nullable type. (the crash message)
    the same test after the fix passed
    cargo test -p vortex-functions -- case_when:: zip:: 113 passed
    cargo +nightly-2026-11-13 fuzz run --dev --sanitizer=none file_scan_expr_v2 crash-71561a38e95bdbd69096c96b41e87ff3cda070c1 -- -runs=1 -rss_limit_mb=0 no crash
    cargo clippy -p {vortex-array, vortex-functions, vortex-python, vortex-fuzz} --all-targets --all-features -- -D warnings clean
    cargo +nightly-2026-11-13 fmt -p vortex-array -p vortex-functions -p vortex-python -p vortex-fuzz nothing to change

    To find the expression, I added a temporary eprintln! of the projection and filter to fuzz/scan_expr.rs and removed it before the review.

    Review

    The fuzz-fix-review skill ran twice, and both reviews approved.

    • First review: two nits. The test only checked is_err(), and it wrote vortex_expr::mask/vortex_expr::cast as full paths. I fixed both: the test now checks the error message and imports the functions at the top of the file.
    • Second review: one nit. The PR changes the public BoolArrayExt::to_mask_fill_null_false signature and should be labelled changelog/break, not changelog/fix.
    • Not checked by the reviewer: it could not run the new test against the unfixed code without a worktree. I ran that check myself, as shown in the first row of the table.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugfuzzer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions