uutils / uutils/coreutils

df: the `--total` row sums per-filesystem rounded-up block counts — wrong totals in release, `attempt to multiply with overflow` with `-h` (exit 134)

Open
#14,459 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - df
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

df --total accumulates the total row's block count as Σ ceil(bytesᵢ / block_size) — summing each filesystem's rounded-up block count instead of rounding the summed bytes once. With a large --block-size every non-empty filesystem rounds up to one block, so the total degenerates into roughly a count of filesystems. The -h path then multiplies that inflated count back by the block size, which overflows. Normal rows take neither path, which is why every non-total row matches GNU exactly and only the total row is wrong.

Steps to reproduce

  • default release build (shipped):
    the total row reports wrong numbers — with -B 10000000000000000000 GNU reports a total of 1 block where uutils reports 29 (or 12E with -h).
$ df       --total -h -B 10000000000000000000 -a | tail -1
total            12E  8.9E   15E  44% -                     # uutils
$ /usr/bin/df --total -h -B 10000000000000000000 -a | tail -1
total                    1     1         1  43% -            # GNU

$ df       --total -B 10000000000000000000 -a | tail -1     # without -h
total                   29    25         9  44% -            # uutils
$ /usr/bin/df --total -B 10000000000000000000 -a | tail -1
total                    1     1         1  43% -            # GNU
  • overflow-checks build:
    adding -h multiplies that inflated count back by the block size and the product overflows u64attempt to multiply with overflow at
    df/src/table.rs:312:17, exit 134.
$ df --total -h -B 10000000000000000000 -a
thread 'main' panicked at src/uu/df/src/table.rs:312:17:
attempt to multiply with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted (core dumped)
$ echo $?
134

Root cause

1. scaled sums per-row ceilings, not the ceiling of the sum.

https://github.com/uutils/coreutils/blob/8118c243f7517b0c1fcf142249ef9b11a87351ad/src/uu/df/src/table.rs#L214-L235

2. The -h branch converts blocks back to bytes with an unguarded multiply.

https://github.com/uutils/coreutils/blob/8118c243f7517b0c1fcf142249ef9b11a87351ad/src/uu/df/src/table.rs#L307-L316

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in df/src/table.rs, especially the block-count accumulation around lines 214-235 and the human-readable conversion around lines 307-316. Run the supplied df --total commands with the large -B value, including -h, to observe the incorrect total and overflow. Done means the total matches GNU for these cases and the -h invocation no longer aborts.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.