uucore's shared size parser (parse_size.rs) supports a % suffix meaning "this percentage of physical memory". It computes (value / 100) * total_physical_memory as an unchecked u128 multiply. A % value large enough to fit in u128 but whose product exceeds u128::MAX overflows, panicking with attempt to multiply with overflow under -C overflow-checks (exit 134);
|
// Special case: for percentage, just compute the given fraction |
|
// of the total physical memory on the machine, if possible. |
|
if unit == "%" { |
|
let number: u128 = Self::parse_number(&numeric_string, 10, size)?; |
|
return match total_physical_memory() { |
|
Ok(total) => Ok((number / 100) * total), |
|
Err(_) => Err(ParseSizeError::PhysicalMem(size.to_string())), |
|
}; |
Because it is shared code with a wide-open default, the panic is reachable from many utils, like du.
$ mkdir -p /tmp/dutest
$ du --block-size=9223372036854775808000000000000% /tmp/dutest
thread 'main' panicked at src/uucore/src/lib/features/parser/parse_size.rs:258:33:
attempt to multiply with overflow
$ echo $?
134
$ DU_BLOCK_SIZE=9223372036854775808000000000000% du /tmp/dutest # same panic via env
The same % value (N = 9223372036854775808000000000000%) panics at parse_size.rs:258:33 from every command below.
| util |
command that triggers the panic |
GNU exit |
| du |
du --block-size=$N /tmp (also DU_BLOCK_SIZE=$N du /tmp) |
0/1 |
| sort |
printf 'b\na\n' > f; sort -S $N f |
2 |
| df |
df --block-size=$N |
1 |
| ls |
ls --block-size=$N /tmp |
2 |
| split |
printf 'x\n' > f; split -b $N f |
1 |
| stdbuf |
stdbuf -o$N true |
125 |
| od |
printf 'x' > f; od -N$N f |
1 |
| shred |
printf 'x' > f; shred --size=$N f |
1 |
| dd |
dd bs=$N (also count=$N, ibs=/obs=/seek=/skip=) |
1 |
| head |
printf 'x' > f; head -c $N f |
1 |
| tail |
printf 'x' > f; tail -c $N f |
1 |
uucore's shared size parser (
parse_size.rs) supports a%suffix meaning "this percentage of physical memory". It computes(value / 100) * total_physical_memoryas an uncheckedu128multiply. A%value large enough to fit inu128but whose product exceedsu128::MAXoverflows, panicking withattempt to multiply with overflowunder-C overflow-checks(exit 134);coreutils/src/uucore/src/lib/features/parser/parse_size.rs
Lines 253 to 260 in 89bdbb8
Because it is shared code with a wide-open default, the panic is reachable from many utils, like
du.The same
%value (N = 9223372036854775808000000000000%) panics atparse_size.rs:258:33from every command below.du --block-size=$N /tmp(alsoDU_BLOCK_SIZE=$N du /tmp)printf 'b\na\n' > f; sort -S $N fdf --block-size=$Nls --block-size=$N /tmpprintf 'x\n' > f; split -b $N fstdbuf -o$N trueprintf 'x' > f; od -N$N fprintf 'x' > f; shred --size=$N fdd bs=$N(alsocount=$N,ibs=/obs=/seek=/skip=)printf 'x' > f; head -c $N fprintf 'x' > f; tail -c $N f