{"record":{"id":"18d4566604d60fa0","repo":"can1357/oh-my-pi","slug":"invalid-zero-length-file-name-18d456","errorCode":null,"errorMessage":"invalid zero-length file name","messagePattern":"invalid zero-length file name","errorType":"error_code","errorClass":"WcError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/wc.rs","lineNumber":789,"sourceCode":"}\n\nimpl TotalWhen {\n\tfn is_total_row_visible(self, num_inputs: usize) -> bool {\n\t\tmatch self {\n\t\t\tSelf::Auto => num_inputs > 1,\n\t\t\tSelf::Always | Self::Only => true,\n\t\t\tSelf::Never => false,\n\t\t}\n\t}\n}\n\n#[derive(Debug, Error)]\nenum WcError {\n\t#[error(\"extra operand {}\\nfile operands cannot be combined with --files0-from\", extra.quote())]\n\tFilesDisabled { extra: Cow<'static, OsStr> },\n\t#[error(\"when reading file names from standard input, no file name of '-' allowed\")]\n\tStdinReprNotAllowed,\n\t#[error(\"invalid zero-length file name\")]\n\tZeroLengthFileName,\n\t#[error(\"{path}:{idx}: invalid zero-length file name\")]\n\tZeroLengthFileNameCtx { path: Cow<'static, str>, idx: usize },\n\t#[error(\"{context}: {source}\")]\n\tIo {\n\t\tcontext: String,\n\t\t#[source]\n\t\tsource:  io::Error,\n\t},\n}\n\nimpl WcError {\n\tfn zero_len(ctx: Option<(&Input, usize)>) -> Self {\n\t\tmatch ctx {\n\t\t\tSome((input, idx)) => {\n\t\t\t\tlet path = match input {\n\t\t\t\t\tInput::Stdin(_) => STDIN_REPR.into(),\n\t\t\t\t\tInput::Path(path) => escape_name_wrapper(path.as_os_str()).into(),","sourceCodeStart":771,"sourceCodeEnd":807,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/wc.rs#L771-L807","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Sanitize the list: drop empty entries before use (e.g. `tr -s '\\0' '\\n' | grep -v '^$' | tr '\\n' '\\0'` or awk)","Fix the producer to never emit empty records (guard against empty variables/lines)","Use ZeroLengthFileNameCtx's variant path/idx info when available to locate the offending record in a file-based list"],"exampleFix":"// before: printf '\\0' > bad.list; wc --files0-from=bad.list\n// after\nfind . -name '*.txt' -print0 > good.list   # guaranteed non-empty names\nwc --files0-from=good.list","handlingStrategy":"validation","validationCode":"fn sanitize_files0_list(bytes: &[u8]) -> Vec<u8> {\n    let mut out = Vec::new();\n    for name in bytes.split(|&b| b == 0).filter(|s| !s.is_empty()) {\n        out.extend_from_slice(name);\n        out.push(0);\n    }\n    out\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never emit NUL terminators for empty inputs in producer scripts","Generate lists with `find ... -print0` or `printf '%s\\0' \"$name\"` with non-empty guarantees","Sanitize (drop empty records from) any externally produced list before use"],"tags":["wc","cli-usage","files0-from","input-validation"],"backgroundTag":"empty-file-name-in-input","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}