{"record":{"id":"560dc1343a398410","repo":"uutils/coreutils","slug":"od-error-skip-past-end","errorCode":null,"errorMessage":"od-error-skip-past-end","messagePattern":"od-error-skip-past-end","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"src/uu/od/src/multifile_reader.rs","lineNumber":157,"sourceCode":"    /// special file (e.g. `/dev/null`, which can be skipped past its empty end).\n    /// Everything else - proc/sys files that report a bogus size, pipes, stdin -\n    /// is advanced by reading and discarding. Skipping past the end of the whole\n    /// input is an error, matching GNU `od`.\n    pub fn skip(&mut self, mut n_skip: u64) -> io::Result<()> {\n        while n_skip > 0 {\n            let Some(curr) = self.curr_file.as_mut() else {\n                break;\n            };\n            n_skip = skip_in_file(curr, n_skip)?;\n            if n_skip == 0 {\n                break;\n            }\n            // Current file is exhausted; continue skipping in the next one.\n            self.next_file();\n        }\n\n        if n_skip > 0 {\n            return Err(io::Error::new(\n                io::ErrorKind::UnexpectedEof,\n                translate!(\"od-error-skip-past-end\"),\n            ));\n        }\n        Ok(())\n    }\n}\n\n/// Skip up to `n_skip` bytes within a single file. Returns the number of bytes\n/// that still need to be skipped (0 if the skip landed inside this file, or\n/// the remainder if the file ended first).\nfn skip_in_file(curr: &mut CurrentReader, n_skip: u64) -> io::Result<u64> {\n    #[cfg(unix)]\n    if let CurrentReader::File(f) = curr\n        && let Ok(meta) = f.metadata()\n    {\n        let size = meta.len();\n        let blksize = uucore::fs::sane_blksize::sane_blksize_from_metadata(&meta);","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/uutils/coreutils/blob/92995feca29e324a7c559ede91db81c32d9f5d59/src/uu/od/src/multifile_reader.rs#L139-L175","documentation":"od's MultifileReader::skip advances through the input files (and file list positions via -N/-j-style skipping) and throws this error when the total available input is shorter than the requested skip amount. It signals 'cannot skip past end of input' with io::ErrorKind::UnexpectedEof.","triggerScenarios":"Running od with a skip larger than the combined input: e.g. `od -j 100000 smallfile`, or `od -j N file1 file2` where N exceeds the sum of file sizes; also with `od -s`/skip options across multiple files where all files are exhausted and n_skip is still > 0.","commonSituations":"Scripts computing skip offsets from assumptions that break (files truncated or empty); piping empty or short input into od with a fixed -j value; using skip values meant for a larger file version.","solutions":["Compare the skip value with actual input size (stat/`wc -c`) and reduce -j accordingly.","Guard in scripts: only pass -j when the input is at least that many bytes.","If the input may legitimately be short, handle the od exit status instead of assuming success.","Check for upstream producers failing/truncating data before od reads it."],"exampleFix":"#!/bin/sh\n# before: od -j 1000000 data.bin  -> error: skip past end\nsize=$(wc -c < data.bin)\nskip=1000000\n# after: clamp skip to available size\n[ \"$size\" -ge \"$skip\" ] || skip=$size\nod -j \"$skip\" data.bin","handlingStrategy":"validation","validationCode":"# Shell: clamp skip to actual input size before od -j\nsize=$(wc -c < input.bin)\nskip=100000\nif [ \"$size\" -lt \"$skip\" ]; then\n  echo \"input too small for -j $skip\" >&2; exit 1\nfi\nod -j \"$skip\" input.bin","typeGuard":null,"tryCatchPattern":"const { status } = spawnSync('od', ['-j', String(skip), file]);\nif (status !== 0) {\n  console.error(`od failed: skip ${skip} exceeds input size ${fs.statSync(file).size}`);\n}","preventionTips":["Compare -j values against wc -c output before running od","Do not assume input files keep a stable size across pipeline runs","Check upstream producers for truncation when od suddenly reports past-end","Handle nonzero od exit codes in scripts instead of chaining blindly"],"tags":["od","eof","skip","cli"],"backgroundTag":"value-out-of-range","analyzedSha":"92995feca29e324a7c559ede91db81c32d9f5d59","analyzedAt":"2026-09-20T12:39:35.476Z","contentChangedAt":"2026-09-20T12:39:35.476Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}