Skip to content

od: fix overflow panic in --traditional label accumulator - #13241

Open
koopatroopa787 wants to merge 2 commits into
uutils:mainfrom
koopatroopa787:fix-od-traditional-label-overflow
Open

koopatroopa787 wants to merge 2 commits into
uutils:mainfrom
koopatroopa787:fix-od-traditional-label-overflow

Conversation

@koopatroopa787

@koopatroopa787 koopatroopa787 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Use wrapping_add in InputOffset::increase_position so od --traditional with a label near u64::MAX wraps like GNU instead of panicking in overflow-checked builds.

Adds a unit test and an integration test in tests/by-util/test_od.rs.

Fixes #13225

Copilot AI review requested due to automatic review settings July 1, 2026 13:07

Copilot AI left a comment

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.

Pull request overview

This PR fixes an overflow panic in od --traditional offset/label accumulation by switching the internal byte position and optional label arithmetic to wrapping semantics, matching GNU od’s unsigned overflow behavior.

Changes:

  • Use wrapping_add for InputOffset::increase_position updates to byte_pos and label.
  • Add a regression unit test to ensure near-u64::MAX labels don’t panic and wrap correctly.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +100 to +104
// A label of u64::MAX must not panic — it wraps, matching C unsigned semantics.
let mut sut = InputOffset::new(Radix::Hexadecimal, 0, Some(u64::MAX));
sut.increase_position(1); // would panic in debug builds before the fix
assert_eq!(sut.label, Some(0));
}
@github-actions

github-actions Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/misc/tty-eof (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/unexpand/bounded-memory is now passing!
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

@sylvestre

Copy link
Copy Markdown
Contributor

please add a test in tests/by-util/test_od.rs too

@koopatroopa787

Copy link
Copy Markdown
Contributor Author

Done — added test_traditional_label_near_u64_max_does_not_panic to tests/by-util/test_od.rs in the latest push. It pipes 16 bytes through od --traditional - 0 0xffffffffffffffff and asserts it succeeds (which would have panicked with exit 101 before the wrapping_add fix).

`InputOffset::increase_position` used plain `+=` / `+` for the running
byte position and user-supplied label, which panics in debug builds (or
any build with `-C overflow-checks=on`) when the label is near
`u64::MAX`. C unsigned arithmetic wraps on overflow, and GNU od silently
wraps in the same situation.

Switch to `wrapping_add` for both fields to match GNU's behaviour and
eliminate the debug-mode panic reported in uutils#13225.

Adds a unit test that exercises the wrap-around path directly.

Fixes uutils#13225
Copilot AI balanced review requested due to automatic review settings October 5, 2026 13:48
@koopatroopa787
koopatroopa787 force-pushed the fix-od-traditional-label-overflow branch from 3769d5f to 39efb9b Compare October 5, 2026 13:48

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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 --traditional offset/label arithmetic overflows on a near-maximal offset (overflow-checks panic; release wraps)

3 participants