Skip to content

od: don't abort on a huge --width#12885

Open
mistaste wants to merge 1 commit into
uutils:mainfrom
mistaste:fix-od-width-overflow
Open

od: don't abort on a huge --width#12885
mistaste wants to merge 1 commit into
uutils:mainfrom
mistaste:fix-od-width-overflow

Conversation

@mistaste

Copy link
Copy Markdown
Contributor

Summary

Fixes #12839.

od -w=<huge> aborted the process while allocating the line buffer:

$ od -w=1162652562662412622 a
memory allocation of 1162652562662412626 bytes failed
Aborted (core dumped)

Change

InputDecoder::new now computes the buffer size with a checked add and reserves
it with try_reserve_exact, returning an io::Error instead of aborting. The
caller maps it to a clean error, matching the graceful out-of-memory behavior of
GNU od:

$ od -w=1162652562662412622 a
od: memory exhausted

A width that does not fit in usize is still rejected by the existing
"argument too large" check.

Checks

  • New regression test test_huge_width_argument; existing od width tests and the input_decoder unit test still pass.
  • cargo fmt clean, cargo clippy -p uu_od --all-targets clean.

`od -w=1162652562662412622` aborted the process while allocating the line
buffer:

    $ od -w=1162652562662412622 a
    memory allocation of 1162652562662412626 bytes failed
    Aborted (core dumped)

`InputDecoder::new` now computes the buffer size with a checked add and
reserves it with `try_reserve_exact`, returning an error instead of aborting.
An out-of-range width is reported cleanly:

    $ od -w=1162652562662412622 a
    od: memory exhausted

Fixes uutils#12839
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/tail-n0f (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

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.

bug(od): when -w is a massive positive number it panics

1 participant