Repository navigation
od: report offset overflow instead of looping - #16514
seragAhmed wants to merge 3 commits into
Conversation
| offset | ||
| .checked_add(n) | ||
| .filter(|&sum| sum <= MAX_OFFSET) | ||
| .ok_or_else(|| USimpleError::new(1, translate!("od-error-offset-overflow"))) |
There was a problem hiding this comment.
We don't need to align error message if we have same meaning. Is it able to .map_err(|e| ..?
There was a problem hiding this comment.
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.
|
GNU testsuite comparison: |
| #[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()); |
There was a problem hiding this comment.
please hardcode "od: offset overflow\n" here, building it from the same error makes the test check nothing
| let sum = offset.saturating_add(n); | ||
| i64::try_from(sum) | ||
| .map(|_| sum) | ||
| .map_err(|e| USimpleError::new(1, e.to_string())) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
3865025 to
20e861c
Compare
Merging this PR will not alter performance1 warning
Comparing Footnotes
|
| } | ||
|
|
||
| #[cfg(target_os = "linux")] | ||
| #[uutests::wasi_ignore(HostPathsNotVisible)] |
There was a problem hiding this comment.
do we need wasi_ignore here? the test is already linux only
There was a problem hiding this comment.
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.
When the offset goes past the largest signed 64-bit file position,
odkept reading forever:od -A d -t u2 -j 9223372036854775804 /dev/zeroprinted one line, then*, and never ended, andod -S 4with the same skip hung with no output.Like GNU (per the issue),
odnow prints the current line, then fails withod: offset overflowand exits 1. Offsets are capped ati64::MAX, the largest signed 64-bit file position, and the same check covers the offset-Sadvances.input_offset.rs:checked_offset_add()returns the new offset or theod-error-offset-overflowerror;InputOffset::increase_positionnow returnsUResult<()>.od.rs: both offset increments use it.en-US.ftl/fr-FR.ftl: the new message.test_skip_near_max_offset_reports_overflowfrom Add as ignored some failing tests found by oss scanner #16493 and adds a unit test for the boundary (exactlyi64::MAXis fine, one more byte fails).Without the fix the regression test times out after 5 s; with it,
test_odpasses (95) anduu_od's unit tests pass (57).cargo clippy -p uu_od --all-targets -- -D warningsandcargo fmt -p uu_od --checkare clean. Run on Linux (Docker,rust:1-bookworm).The
--traditionallabel offset is still increased unchecked; that's a separate case (see #13241).Closes #16498