cksum: reject oversized SHAKE --length instead of aborting#12881
Open
mistaste wants to merge 1 commit into
Open
cksum: reject oversized SHAKE --length instead of aborting#12881mistaste wants to merge 1 commit into
mistaste wants to merge 1 commit into
Conversation
|
GNU testsuite comparison: |
e45f148 to
2c84e73
Compare
A huge `--length` with `--algorithm shake128`/`shake256` (e.g.
`--length 10011111117721172727`) made cksum abort while trying to
allocate the output buffer:
memory allocation of 1251388889715146591 bytes failed
SHAKE is an extendable-output function with no inherent maximum, but the
digest still has to be materialized and hex-encoded in memory. Cap the
requested length at MAX_SHAKE_OUTPUT_BITS and return a clean error for
larger requests instead of letting the allocation abort the process.
Fixes uutils#12869
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12869.
cksum --algorithm shake128/shake256with a very large--lengthaborts theprocess while allocating the output buffer:
SHAKE is an extendable-output function with no inherent maximum, but the digest
still has to be materialized and hex-encoded in memory, so an unbounded
--lengthturns into an unbounded allocation that aborts the process instead ofproducing a clean error.
Change
MAX_SHAKE_OUTPUT_BITSand aChecksumError::ShakeLengthTooBigvariant inuucore::checksum.--lengthup front incksum(next to the existing SHA/BLAKElength validation) and reject oversized requests with a clear error rather than
letting the allocation abort.
test_shake_length_too_largecovering bothshake128andshake256.This mirrors the approach used in the recent
datewidth fix (aMAX_*bound thatturns an unbounded allocation request into a graceful error).
Note
The cap (
u32::MAXbits ≈ 512 MiB) is intentionally generous — it only rejectsabsurd values and doesn't affect any realistic length. Happy to adjust the bound
if you'd prefer a different limit.
Checklist
cargo fmt— cleancargo clippy -p uu_cksum— cleancargo test -p coreutils --features cksum test_shake— 27 passed