Skip to content

Conversation

@vjardin
Copy link

@vjardin vjardin commented Feb 12, 2026

The old RoundUp formula fsize + fsize % size was incorrect. For example, truncate -s %128K on a 24696-byte file produced 49392 bytes instead of the correct 131072 bytes.

Maybe, this was incidentally fixed in commit fe97933 ("truncate: eliminate duplicate stat() syscall") by replacing the formula with fsize.checked_next_multiple_of(size). However, the existing test test_round_up used values (fsize=10, size=4) where both the buggy and correct formulas give the same result (12), so the bug was never caught by the test suite.

Add unit and integration tests that would have caught this bug:

  • File smaller than rounding unit (the reported scenario)
  • File larger than rounding unit but not aligned
  • File already aligned to the rounding unit
  • Division by zero (RoundUp with size=0)

Link: https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/48210

The old RoundUp formula `fsize + fsize % size` was incorrect. For
example, `truncate -s %128K` on a 24696-byte file produced 49392
bytes instead of the correct 131072 bytes.

This was incidentally fixed in commit fe97933 ("truncate: eliminate
duplicate stat() syscall") by replacing the formula with
`fsize.checked_next_multiple_of(size)`. However, the existing test
`test_round_up` used values (fsize=10, size=4) where both the buggy
and correct formulas give the same result (12), so the bug was never
caught by the test suite.

Add unit and integration tests that would have caught this bug:
- File smaller than rounding unit (the reported scenario)
- File larger than rounding unit but not aligned
- File already aligned to the rounding unit
- Division by zero (RoundUp with size=0)

Link: https://review.trustedfirmware.org/c/TF-A/trusted-firmware-a/+/48210
Signed-off-by: Vincent Jardin <vjardin@free.fr>
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/cut/bounded-memory. tests/cut/bounded-memory is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/pr/bounded-memory. tests/pr/bounded-memory is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/shuf/shuf-reservoir (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/sort/sort-stale-thread-mem (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/printf/printf-surprise is now passing!

@vjardin
Copy link
Author

vjardin commented Feb 13, 2026

I am not expert with coreutils' CI ; but checking some others, it seems to be 2 scenarios that are used to fail ; I do not see how they are related to this commit.

The purpose of this contribution is to avoid other regressions that lead to wrong sizes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant