Skip to content

Fix cksum oom panic#12930

Closed
killuazoldyck680 wants to merge 10 commits into
uutils:mainfrom
killuazoldyck680:fix-cksum-oom-panic
Closed

Fix cksum oom panic#12930
killuazoldyck680 wants to merge 10 commits into
uutils:mainfrom
killuazoldyck680:fix-cksum-oom-panic

Conversation

@killuazoldyck680

Copy link
Copy Markdown

Hey made some more changes, a review would be helpful

Instead of allowing the process to panic and trigger an kernel abort (Aborted (core dumped)), I have implemented a try_reserve check with a safety cushion inside the parsing stage. If memory allocation is bound to fail, it now gracefully returns a clean cksum: memory exhausted error string.

@oech3 (I've updated the logic to handle the specific test scenario you requested!)

Fixes #12869

Comment thread src/uu/cksum/src/cksum.rs Outdated
Ok(0) => Ok(None),
Ok(l) => Ok(Some(HashLength::from_bits(l))),
Ok(l) => {
let bytes_needed = (l + 7) / 8;

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.

what is 7 and 8 ?
it should be documented

Comment thread src/uu/cksum/src/cksum.rs Outdated
let bytes_needed = (l + 7) / 8;

let mut test_buffer: Vec<u8> = Vec::new();
let safety_cushion = bytes_needed.saturating_add(65536);

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.

what is 65536 ?

Comment thread src/uu/cksum/src/cksum.rs Outdated
let safety_cushion = bytes_needed.saturating_add(65536);

if test_buffer.try_reserve(safety_cushion).is_err() {
return Err(uucore::error::USimpleError::new(1, "memory exhausted"));

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.

needs translate!()

Comment thread src/uu/false/locales/en-US.ftl Outdated
false-help-text = Print help information
false-version-text = Print version information

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.

unrelated change

@sylvestre sylvestre 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.

needs more love

@oech3

oech3 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@sylvestre Please review #12925 (comment) . We probably should not label "good 1st issue" for OOM issue.

@github-actions

github-actions Bot commented Jun 16, 2026

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/misc/io-errors (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cut/cut-huge-range is now being skipped but was previously passing.
Note: The gnu test tests/dd/no-allocate is now being skipped but was previously passing.
Congrats! The gnu test tests/expand/bounded-memory is now passing!

@killuazoldyck680

Copy link
Copy Markdown
Author

thank you for pointing out the mistakes @sylvestre will try work on these.

@killuazoldyck680

killuazoldyck680 commented Jun 16, 2026

Copy link
Copy Markdown
Author

hey, another set of changes, these should be more in line with the ones you requested.

Changes made

  1. Moved from raw, magic numbers to named constants.
  2. Introduced const BITS_PER_BYTE: usize = 8; to explicitly represent byte boundaries.
    Introduced const OOM_SAFETY_CUSHION_BYTES: usize = 65536; to represent the 64 KiB memory safety margin.
    Organized both declarations at the top of the block scope to strictly adhere to the project's idiomatic clippy::items_after_statements lint rule.
  3. Adopted Idiomatic Standard Library Math div_ceil.
  4. This resolves the FreeBSD/OpenBSD cargo clippy failures regarding the manual reimplementation of standard library math features while improving code readability.
  5. Added translate!() to the error message.

@oech3

oech3 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

test_buffer is TOCTOU race. Neve do that.

@oech3

oech3 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Sorry. But this approach is not acceptible. But if you still want to try this, please change the approach in #12931 to propagate err.

@killuazoldyck680

Copy link
Copy Markdown
Author

hey, @oech3 thanks for replying, will try a different approach.

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(cksum): panics when using an algorithm shake128 and shake256 with an extremly large length

3 participants