uutils / uutils/coreutils

od `--traditional` offset/label arithmetic overflows on a near-maximal offset (overflow-checks panic; release wraps)

Open
#13,225 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - od
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

In --traditional mode, od accepts an explicit pseudo-address label. A label near u64::MAX makes the offset accumulator overflow: InputOffset::increase_position adds the bytes-read n to the running position/label with unchecked u64 arithmetic (self.byte_pos += n, self.label = Some(l + n)). With a label of 0xffffffffffffffff, the very first read overflows that add.

It panics only under overflow-checks (debug builds, or a release build compiled with -C overflow-checks=on).

$ printf '0123456789ABCDEF' | ./target/debug/od --traditional - 0 0xffffffffffffffff
thread 'main' panicked at src/uu/od/src/input_offset.rs:40:31:
attempt to add with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo $?
101

Root cause

// src/uu/od/src/input_offset.rs
/// Increase `byte_pos` and `label` if a label is used.
pub fn increase_position(&mut self, n: u64) {
    self.byte_pos += n;                 // unchecked
    if let Some(l) = self.label {
        self.label = Some(l + n);       // <- input_offset.rs:40:31, overflows when l ≈ u64::MAX
    }
}

label comes directly from the --traditional pseudo-address argument (0xffffffffffffffff here = u64::MAX), and byte_pos from the (also user-influenceable) starting offset. Adding the per-read byte count n with plain +/+= overflows.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the near-maximal-label command from the issue, then read src/uu/od/src/input_offset.rs and inspect InputOffset::increase_position. Trace how --traditional parses and uses the label, and check existing od tests for overflow behavior. Done means the supplied input no longer panics when the label or offset approaches u64::MAX, with behavior covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.