can1357/oh-my-pi · error · WcError

invalid zero-length file name

Error message

invalid zero-length file name

What it means

WcError::ZeroLengthFileName is raised when a zero-length (empty) file name is encountered in the `--files0-from` input. Empty names can only result from malformed input (consecutive NULs, leading/trailing NUL) and are rejected per POSIX/coreutils semantics.

Source

Thrown at crates/pi-builtins/src/wc.rs:789

}

impl TotalWhen {
	fn is_total_row_visible(self, num_inputs: usize) -> bool {
		match self {
			Self::Auto => num_inputs > 1,
			Self::Always | Self::Only => true,
			Self::Never => false,
		}
	}
}

#[derive(Debug, Error)]
enum WcError {
	#[error("extra operand {}\nfile operands cannot be combined with --files0-from", extra.quote())]
	FilesDisabled { extra: Cow<'static, OsStr> },
	#[error("when reading file names from standard input, no file name of '-' allowed")]
	StdinReprNotAllowed,
	#[error("invalid zero-length file name")]
	ZeroLengthFileName,
	#[error("{path}:{idx}: invalid zero-length file name")]
	ZeroLengthFileNameCtx { path: Cow<'static, str>, idx: usize },
	#[error("{context}: {source}")]
	Io {
		context: String,
		#[source]
		source:  io::Error,
	},
}

impl WcError {
	fn zero_len(ctx: Option<(&Input, usize)>) -> Self {
		match ctx {
			Some((input, idx)) => {
				let path = match input {
					Input::Stdin(_) => STDIN_REPR.into(),
					Input::Path(path) => escape_name_wrapper(path.as_os_str()).into(),

View on GitHub (pinned to 9690622007)

Solutions

  1. Sanitize the list: drop empty entries before use (e.g. `tr -s '\0' '\n' | grep -v '^$' | tr '\n' '\0'` or awk)
  2. Fix the producer to never emit empty records (guard against empty variables/lines)
  3. Use ZeroLengthFileNameCtx's variant path/idx info when available to locate the offending record in a file-based list

Example fix

// before: printf '\0' > bad.list; wc --files0-from=bad.list
// after
find . -name '*.txt' -print0 > good.list   # guaranteed non-empty names
wc --files0-from=good.list
Defensive patterns

Strategy: validation

Validate before calling

fn sanitize_files0_list(bytes: &[u8]) -> Vec<u8> {
    let mut out = Vec::new();
    for name in bytes.split(|&b| b == 0).filter(|s| !s.is_empty()) {
        out.extend_from_slice(name);
        out.push(0);
    }
    out
}

Prevention

When it happens

Trigger: A --files0-from list containing "\0" sequences: two adjacent NUL bytes, an empty line of NULs from `printf '\0'`, or a truncated writer that emitted a lone NUL terminator with no name before it.

Common situations: Bugs in the script generating the list (e.g. `echo "" | tr '\n' '\0'`); xargs -0 fed empty strings; a producer crashed mid-write leaving stray NULs.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/18d4566604d60fa0. Report an issue: GitHub.