zed-industries/zed · error · io::Error
path contains interior NUL: {}
Error message
path contains interior NUL: {} What it means
Returned by path_to_c_string when the path being passed to a Unix syscall contains an interior NUL byte, which C strings cannot represent. The offending path (shown with {:?}) is rejected up front instead of producing a truncated/wrong path at the syscall boundary.
Source
Thrown at crates/fs/src/fs.rs:673
use windows::core::PCWSTR;
let source: Vec<u16> = source.as_os_str().encode_wide().chain(Some(0)).collect();
let target: Vec<u16> = target.as_os_str().encode_wide().chain(Some(0)).collect();
unsafe {
MoveFileExW(
PCWSTR(source.as_ptr()),
PCWSTR(target.as_ptr()),
MOVE_FILE_FLAGS::default(),
)
}
.map_err(|_| io::Error::last_os_error())
}
#[cfg(any(target_os = "macos", target_os = "linux"))]
fn path_to_c_string(path: &Path) -> io::Result<CString> {
CString::new(path.as_os_str().as_bytes()).map_err(|_| {
io::Error::new(
io::ErrorKind::InvalidInput,
format!("path contains interior NUL: {}", path.display()),
)
})
}
// On Unix targets, std::fs::ReadDir panics in its Drop implementation
// when an unexpected error is returned from closedir(2). We hit this
// condition in production; one cause seems to be macOS's FSEventStream
// incorrectly closing fds it doesn't own, resulting in closedir returning
// EBADF, see https://github.com/zed-industries/zed/issues/59952#issuecomment-5080178879.
//
// We also see occasional errors like ENXIO and ETIMEDOUT that seem to
// come from network or other exotic filesystems.
//
// To avoid crashing the app in this situation, we use the rustix analogue of
// ReadDir, which doesn't have this panic in drop.
#[cfg(unix)]View on GitHub (pinned to 9d272b0363)
Solutions
- Strip or reject NUL bytes in user-provided paths before filesystem operations
- Treat the path as invalid input and surface an error to the caller
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/fs/src/fs.rs:628 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20).
Data as JSON: /api/errors/f51affb4b17c3e7b.
Report an issue: GitHub.