uutils/coreutils · error · io::Error

od-error-skip-past-end

Error message

od-error-skip-past-end

What it means

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.

Solutions

  1. Compare the skip value with actual input size (stat/`wc -c`) and reduce -j accordingly.
  2. Guard in scripts: only pass -j when the input is at least that many bytes.
  3. If the input may legitimately be short, handle the od exit status instead of assuming success.
  4. Check for upstream producers failing/truncating data before od reads it.

Example fix

#!/bin/sh
# before: od -j 1000000 data.bin  -> error: skip past end
size=$(wc -c < data.bin)
skip=1000000
# after: clamp skip to available size
[ "$size" -ge "$skip" ] || skip=$size
od -j "$skip" data.bin
Defensive patterns

Strategy: validation

Validate before calling

# Shell: clamp skip to actual input size before od -j
size=$(wc -c < input.bin)
skip=100000
if [ "$size" -lt "$skip" ]; then
  echo "input too small for -j $skip" >&2; exit 1
fi
od -j "$skip" input.bin

Try / catch

const { status } = spawnSync('od', ['-j', String(skip), file]);
if (status !== 0) {
  console.error(`od failed: skip ${skip} exceeds input size ${fs.statSync(file).size}`);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of uutils/coreutils@92995feca2 (2026-09-20). Data as JSON: /api/errors/560dc1343a398410. Report an issue: GitHub.

Appendix: source

Thrown at src/uu/od/src/multifile_reader.rs:157

    /// special file (e.g. `/dev/null`, which can be skipped past its empty end).
    /// Everything else - proc/sys files that report a bogus size, pipes, stdin -
    /// is advanced by reading and discarding. Skipping past the end of the whole
    /// input is an error, matching GNU `od`.
    pub fn skip(&mut self, mut n_skip: u64) -> io::Result<()> {
        while n_skip > 0 {
            let Some(curr) = self.curr_file.as_mut() else {
                break;
            };
            n_skip = skip_in_file(curr, n_skip)?;
            if n_skip == 0 {
                break;
            }
            // Current file is exhausted; continue skipping in the next one.
            self.next_file();
        }

        if n_skip > 0 {
            return Err(io::Error::new(
                io::ErrorKind::UnexpectedEof,
                translate!("od-error-skip-past-end"),
            ));
        }
        Ok(())
    }
}

/// Skip up to `n_skip` bytes within a single file. Returns the number of bytes
/// that still need to be skipped (0 if the skip landed inside this file, or
/// the remainder if the file ended first).
fn skip_in_file(curr: &mut CurrentReader, n_skip: u64) -> io::Result<u64> {
    #[cfg(unix)]
    if let CurrentReader::File(f) = curr
        && let Ok(meta) = f.metadata()
    {
        let size = meta.len();
        let blksize = uucore::fs::sane_blksize::sane_blksize_from_metadata(&meta);

View on GitHub (pinned to 92995feca2)