Bug 16054

Summary: du: size overflow
Product: Busybox Reporter: sertonix
Component: OtherAssignee: unassigned
Status: NEW ---    
Severity: normal CC: busybox-cvs
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:
Attachments: Minimal config

Description sertonix 2024-05-01 14:10:25 UTC
Created attachment 9742 [details]
Minimal config

busybox `du` stores the size sum as `unsigned long long`. This works (with musl at least) until ~16 Exabytes (`2^64-1`) but overflows beyond that due to missing overflow check. This size can be reached with sparse files.

(Run in a tmpfs. Otherwise `dd` may throw size errors)
```sh
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 prints `Infinity` and a 0 exit code. I think a non zero exit code makes more sense but that is debatable.

Downstream issue: https://gitlab.alpinelinux.org/alpine/aports/-/issues/16075