Skip to content

Validate min_unit in bs_size_human_readable - #180

Merged
vojtechtrefny merged 1 commit into
storaged-project:mainfrom
wxllll:fix/human-readable-min-unit-up-010
Oct 22, 2026
Merged

vojtechtrefny merged 1 commit into
storaged-project:mainfrom
wxllll:fix/human-readable-min-unit-up-010

Conversation

@wxllll

@wxllll wxllll commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

bs_size_human_readable() only normalizes BS_BUNIT_UNDEF, allowing other unsupported min_unit values to index past b_units. This is also reachable through Python's human_readable("KB") and human_readable("MB"), since those names map to decimal unit values.

Normalize values outside B through YiB to B before scaling or indexing. This preserves valid binary units and the existing UNDEF fallback. B is the minimum unit, so automatic promotion to larger binary units still applies. Add regression coverage for integer boundaries and decimal unit names, including zero, positive and negative sizes with both translation settings.

Validated with GCC and Clang builds and make check, GCC make ci, and 60 native C API cases under ASan/UBSan. The new Python regressions crash against the original C implementation and pass with the fix. Three Python test executions per full suite were skipped because the required ps_AF.UTF-8 locale name is unavailable. Alpine/musl and csmock CI were not run locally

Summary by CodeRabbit

  • Bug Fixes
    • Human-readable size formatting now handles minimum units outside the supported binary-unit range consistently, using bytes as the fallback. Decimal minimum-unit values produce the same output as omitting the minimum unit.
  • Documentation
    • Clarified how unsupported minimum-unit values are handled.

Only BS_BUNIT_UNDEF is normalized to bytes. Other values outside the
binary unit range can index past b_units, including decimal units
passed through the Python human_readable() wrapper.

Treat unsupported values as B before scaling and indexing, preserving
the existing UNDEF fallback. B remains the minimum unit, so larger sizes
can still be promoted to other binary units.

Add regression coverage for the range boundaries, invalid integer
values and decimal unit names, with zero and signed sizes and both
translation modes.
@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: storaged-project/libbytesize/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ee4670f8-f14b-44d2-b96b-fc84dcbeb2d2
📥 Commits

Reviewing files that changed from the base of the PR and between 76eccb3 and fd7dd43.

📒 Files selected for processing: 3
  • src/bs_size.c
  • tests/lbs_py_override_unittest.py
  • tests/libbytesize_unittest.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Minimum-unit values outside the binary-unit range now fall back to bytes. Tests cover invalid and decimal minimum units, translation settings, and formatting in KiB and YiB.

Changes: Human-readable minimum units

Layer / File(s) Summary
Normalize minimum units and verify formatting
src/bs_size.c, tests/libbytesize_unittest.py, tests/lbs_py_override_unittest.py
Out-of-range min_unit values now fall back to BS_BUNIT_B. Tests compare output for invalid and decimal minimum units and check formatting for 1.5 KiB and 1.5 YiB.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to fd7dd

Out-of-range and decimal minimum units fall back to byte-based formatting, while valid binary units retain their behavior. No remaining merge risk is evident.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: validating min_unit in bs_size_human_readable.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vojtechtrefny

Copy link
Copy Markdown
Member

Jenkins, ok to test.

@vojtechtrefny vojtechtrefny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you.

@vojtechtrefny
vojtechtrefny merged commit 045b003 into storaged-project:main Oct 22, 2026
34 of 35 checks passed
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.

2 participants