zed-industries/zed · error · std::io::Error

invalid argument: path or argument contains null byte

Error message

invalid argument: path or argument contains null byte

What it means

Sentinel io::Error (InvalidInput) raised by invalid_input_error and returned by spawn_posix_spawn when the program path or any argument contains a NUL byte. POSIX exec APIs are NUL-terminated C strings, so such a command can never be spawned.

Source

Thrown at crates/util/src/command/darwin.rs:566

    };
    if fd == -1 {
        return Err(io::Error::last_os_error());
    }
    Ok(unsafe { std::fs::File::from_raw_fd(fd) })
}

/// Zero means `Ok()`, all other values are treated as raw OS errors. Does not look at `errno`.
/// Mirrored after Rust's std `cvt_nz` function.
fn cvt_nz(error: libc::c_int) -> io::Result<()> {
    if error == 0 {
        Ok(())
    } else {
        Err(io::Error::from_raw_os_error(error))
    }
}

fn invalid_input_error() -> io::Error {
    io::Error::new(
        io::ErrorKind::InvalidInput,
        "invalid argument: path or argument contains null byte",
    )
}

#[cfg(test)]
mod tests {
    use std::os::unix::process::ExitStatusExt as _;

    use super::*;
    use futures_lite::AsyncWriteExt;

    // Verifies that pipes returned by `create_pipe` aren't visible to unrelated
    // child processes spawned via `std::process::Command`. On macOS, `std`
    // uses `posix_spawn` without `POSIX_SPAWN_CLOEXEC_DEFAULT`, so any
    // non-CLOEXEC fd in the parent leaks into the child. Without
    // `FD_CLOEXEC` on our pipe fds, an unrelated spawn (a terminal, the crash
    // handler, etc.) running concurrently with a piped git child would hold

View on GitHub (pinned to f4178619ac)

Solutions

  1. Find where the null byte enters the path or argument (usually corrupted input or bad string truncation)
  2. Sanitize or reject arguments containing interior NUL bytes before spawning
  3. Log the offending command to locate the source of the embedded null
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/util/src/command/darwin.rs:566 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/c483d35f2d853744. Report an issue: GitHub.