Skip to content

Fix IndexError in convert_size_bytes_to_string for sizes >= 1024 YB#186

Open
SAY-5 wants to merge 1 commit into
fabiocaccamo:mainfrom
SAY-5:fix-convert-size-bytes-overflow
Open

Fix IndexError in convert_size_bytes_to_string for sizes >= 1024 YB#186
SAY-5 wants to merge 1 commit into
fabiocaccamo:mainfrom
SAY-5:fix-convert-size-bytes-overflow

Conversation

@SAY-5

@SAY-5 SAY-5 commented Jun 20, 2026

Copy link
Copy Markdown

Describe your changes
convert_size_bytes_to_string() raised IndexError for any size of 1024 YB or more (2**90 bytes and up), because the unit-selection loop guard factor <= factor_limit let the index increment one past the last SIZE_UNITS entry before units[factor] was read. Changing the guard to factor < factor_limit stops at the largest unit and clamps the value to YB instead of crashing. Smaller sizes are unaffected.

Related issue
#184

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests for the proposed changes.
  • I have run the tests and there are not errors.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@codecov

codecov Bot commented Jun 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.33%. Comparing base (c98dbf6) to head (b6bc4f3).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #186   +/-   ##
=======================================
  Coverage   98.33%   98.33%           
=======================================
  Files          13       13           
  Lines         780      780           
=======================================
  Hits          767      767           
  Misses         13       13           
Flag Coverage Δ
unittests 98.33% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@fabiocaccamo

Copy link
Copy Markdown
Owner

@SAY-5 thank you for this PR, could you please add tests for converting from string to size and also ensure that size -> string -> size returns the initial value?

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