dd: don't panic on huge count/skip/seek operands#12884
Open
mistaste wants to merge 1 commit into
Open
Conversation
A very large `count=`, `skip=`, `seek=`, `iseek=` or `oseek=` operand
overflowed an internal `blocks * block_size` multiplication and aborted the
process:
$ dd if=a of=b count=177817277272177278
thread 'main' panicked at src/uu/dd/src/dd.rs: attempt to multiply with overflow
`Num::to_bytes` now uses `saturating_mul`, so an out-of-range block count
saturates to `u64::MAX` and is caught by the existing `> i64::MAX` (intmax_t)
limit checks for `skip`/`seek` instead of panicking. The same `i64::MAX` limit
is now also enforced for `count`, which previously had no check and overflowed
later in `calc_loop_bsize`.
These operands now report a clean error, matching GNU:
$ dd count=177817277272177278
dd: invalid number: '...': Value too large for defined data type
Fixes uutils#12843
Fixes uutils#12845
Fixes uutils#12846
Fixes uutils#12848
|
GNU testsuite comparison: |
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 #12843, #12845, #12846, #12848.
A very large
count=,skip=,seek=,iseek=oroseek=operand overflowedan internal
blocks * block_sizemultiplication and aborted the process:Change
Num::to_bytesnow usessaturating_mul, so an out-of-range block countsaturates to
u64::MAXand is caught by the existing> i64::MAX(intmax_t)limit checks for
skip/seekinstead of panicking.i64::MAXlimit is now also enforced forcount, which previouslyhad no check and overflowed later in
calc_loop_bsize.These operands now report a clean error, matching GNU:
Checks
test_large_numeric_operands_do_not_panic(covers count/skip/seek/iseek/oseek); existing dd tests still pass.cargo fmtclean,cargo clippy -p uu_dd --all-targetsclean.