main/busybox: du size overflow
busybox du
stores the size sum as unsigned long long
. This works until ~16 Exabytes (2^64-1
) but overflows beyond that due to missing overflow check. That may be unlikely but sparse files can do that.
(Run in a tmpfs. Otherwise dd
may throw size errors)
dd if=/dev/null bs=1 seek=$(echo '2^63-1' | bc) of=a
dd if=/dev/null bs=1 seek=$(echo '2^63-1' | bc) of=b
printf 12 > more
busybox du -bc a b
=> 18446744073709551614 total
busybox du -bc a b more
=> 0 total
The du
implementation of coreutils returns Infinity
(instead of 0) and a 0 exit code. I don't like the approach of coreutils. I think du
should return a non zero exit code if it can't return the correct size and then the printed value is irrelevant.
It seems unlikely that this can cause real issues but may be worth fixing.
CC @nmeum