Skip to content

od: report offset overflow instead of looping - #16514

Open
seragAhmed wants to merge 3 commits into
uutils:mainfrom
seragAhmed:fix/16498-od-offset-overflow
Open

seragAhmed wants to merge 3 commits into
uutils:mainfrom
seragAhmed:fix/16498-od-offset-overflow

Conversation

@seragAhmed

Copy link
Copy Markdown

When the offset goes past the largest signed 64-bit file position, od kept reading forever: od -A d -t u2 -j 9223372036854775804 /dev/zero printed one line, then *, and never ended, and od -S 4 with the same skip hung with no output.

Like GNU (per the issue), od now prints the current line, then fails with od: offset overflow and exits 1. Offsets are capped at i64::MAX, the largest signed 64-bit file position, and the same check covers the offset -S advances.

  • input_offset.rs: checked_offset_add() returns the new offset or the od-error-offset-overflow error; InputOffset::increase_position now returns UResult<()>.
  • od.rs: both offset increments use it.
  • en-US.ftl / fr-FR.ftl: the new message.
  • Enables the ignored test_skip_near_max_offset_reports_overflow from Add as ignored some failing tests found by oss scanner  #16493 and adds a unit test for the boundary (exactly i64::MAX is fine, one more byte fails).

Without the fix the regression test times out after 5 s; with it, test_od passes (95) and uu_od's unit tests pass (57). cargo clippy -p uu_od --all-targets -- -D warnings and cargo fmt -p uu_od --check are clean. Run on Linux (Docker, rust:1-bookworm).

The --traditional label offset is still increased unchecked; that's a separate case (see #13241).

Closes #16498

Comment thread src/uu/od/src/input_offset.rs Outdated
offset
.checked_add(n)
.filter(|&sum| sum <= MAX_OFFSET)
.ok_or_else(|| USimpleError::new(1, translate!("od-error-offset-overflow")))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to align error message if we have same meaning. Is it able to .map_err(|e| ..?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3865025: dropped the custom offset overflow message and its translations, and now map the i64::try_from error with .map_err; the test builds the expected stderr from that error.

@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/printf/printf. tests/printf/printf is passing on 'main'. Maybe you have to rebase?

Comment thread tests/by-util/test_od.rs Outdated
#[ignore = "an offset overflow must be diagnosed"]
fn test_skip_near_max_offset_reports_overflow() {
let skip = (i64::MAX - 3).to_string();
let err = format!("od: {}\n", i64::try_from(u64::MAX).unwrap_err());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please hardcode "od: offset overflow\n" here, building it from the same error makes the test check nothing

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded it in 20e861c.

Comment thread src/uu/od/src/input_offset.rs Outdated
let sum = offset.saturating_add(n);
i64::try_from(sum)
.map(|_| sum)
.map_err(|e| USimpleError::new(1, e.to_string()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this now prints "od: out of range integral type conversion attempted", GNU says "od: offset overflow"
please keep the translated "offset overflow" message, the Rust error text means nothing to a user

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated checked_offset_add to keep USimpleError::new(1, translate!("od-error-offset-overflow")) instead of e.to_string(), and hardcoded "od: offset overflow\n" in test_skip_near_max_offset_reports_overflow(). Also rebased onto main to resolve the unrelated tests/printf/printf GNU comparison failure.

When the input offset goes past the largest signed 64-bit file
position, for example `od -j 9223372036854775804 /dev/zero`, od kept
reading forever (or printed `*` and never ended). Like GNU, print the
current line, then fail with "od: offset overflow" and exit 1. The
same check applies to the offsets tracked by -S.

Closes uutils#16498
The Rust conversion error text ("out of range integral type conversion
attempted") means nothing to a user; report GNU's "offset overflow"
through the translated message instead. Hardcode the expected stderr in
the test so it checks the message, and skip the test under WASI, where
/dev/zero is not visible.
@seragAhmed
seragAhmed force-pushed the fix/16498-od-offset-overflow branch from 3865025 to 20e861c Compare November 15, 2026 15:39
@codspeed

codspeed Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 3 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 6 untouched benchmarks
⏩ 470 skipped benchmarks1


Comparing seragAhmed:fix/16498-od-offset-overflow (20e861c) with main (b5223da)

Open in CodSpeed

Footnotes

  1. 470 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

Comment thread tests/by-util/test_od.rs
}

#[cfg(target_os = "linux")]
#[uutests::wasi_ignore(HostPathsNotVisible)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need wasi_ignore here? the test is already linux only

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The WASI job builds the integration tests for the Linux host and only runs the binary under wasmtime, so cfg(target_os = "linux") is still true there. /dev/zero isn't preopened in the guest, so the test failed in the WASI run of 3865025 (run 43717059476): od -A d -t u2 -j 9223372036854775804 /dev/zero printed nothing. test_skip_bytes_proc_file_without_seeking in this file uses the same cfg(linux) + wasi_ignore(HostPathsNotVisible) pair for /proc/version.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

od: hangs instead of reporting offset overflow

3 participants