Skip to content

Fuzz: arithmetic_fuzz panic on malformed ${#[} — intermittent CI failures #882

@chaliy

Description

@chaliy

Summary

The arithmetic_fuzz target found a panic in expand_brace_expr_in_arithmetic when processing the input [${#[ (bytes [91, 36, 123, 35, 91]).

Failing CI runs

All three failures are in Fuzz Test (arithmetic_fuzz) — parser and lexer fuzz targets pass.

Root cause

In crates/bashkit/src/interpreter/mod.rs, expand_brace_expr_in_arithmetic:

if let Some(bracket) = rest.find('[') {
    let idx = &rest[bracket + 1..rest.len().saturating_sub(1)];

When rest = "[" (from input ${#[}), bracket = 0, rest.len() = 1, so saturating_sub(1) = 0, producing the slice rest[1..0] which panics with:

byte range starts at 1 but ends at 0

Reproduce

cargo fuzz run arithmetic_fuzz -- -runs=0  # then with the crash artifact
# Or directly:
echo '$((0 + ${#[}))' | cargo run -p bashkit-cli

Fix

Guard bracket + 1 > end before slicing — return "0" for malformed expressions.

Fixed in commit ffdad8d on branch claude/run-maintenance-fIcsd with regression test arithmetic_malformed_brace_length_no_panic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions