From b6bc4f3800ee86bd536b46c820dae8f8967a4bf8 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Sat, 20 Jun 2026 12:18:23 -0700 Subject: [PATCH 1/2] Fix IndexError in convert_size_bytes_to_string for sizes >= 1024 YB Signed-off-by: Sai Asish Y --- src/fsutil/converters.py | 2 +- tests/test_converters.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fsutil/converters.py b/src/fsutil/converters.py index 2399269..c83f199 100644 --- a/src/fsutil/converters.py +++ b/src/fsutil/converters.py @@ -11,7 +11,7 @@ def convert_size_bytes_to_string(size: int) -> str: units = SIZE_UNITS factor = 0 factor_limit = len(units) - 1 - while (size_num >= 1024) and (factor <= factor_limit): + while (size_num >= 1024) and (factor < factor_limit): size_num /= 1024 factor += 1 size_units = units[factor] diff --git a/tests/test_converters.py b/tests/test_converters.py index f7e95f1..356bfb4 100644 --- a/tests/test_converters.py +++ b/tests/test_converters.py @@ -13,6 +13,9 @@ (1073741824, "1.00 GB"), (1879048192, "1.75 GB"), (1099511627776, "1.00 TB"), + (2**80, "1.00 YB"), + (2**90, "1024.00 YB"), + (2**100, "1048576.00 YB"), ], ) def test_convert_size_bytes_to_string(size_bytes, expected_output): From 45bdca4527b40c18d7f2df4bf6f0af1b4aa102a7 Mon Sep 17 00:00:00 2001 From: Sai Asish Y Date: Fri, 26 Jun 2026 15:20:16 -0700 Subject: [PATCH 2/2] Add tests for YB-range string conversion and round-trip --- tests/test_converters.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_converters.py b/tests/test_converters.py index 356bfb4..3518cca 100644 --- a/tests/test_converters.py +++ b/tests/test_converters.py @@ -54,6 +54,9 @@ def test_convert_size_bytes_to_string_and_convert_size_string_to_bytes( ("1.00 MB", 1048576), ("1.00 GB", 1073741824), ("1.00 TB", 1099511627776), + ("1.00 YB", 2**80), + ("1024.00 YB", 2**90), + ("1048576.00 YB", 2**100), ], ) def test_convert_size_string_to_bytes(size_string, expected_output): @@ -72,6 +75,9 @@ def test_convert_size_string_to_bytes(size_string, expected_output): (1170378588, 1170378588), (2136746229, 2136746229), (1099511627776, 1099511627776), + (2**80, 2**80), + (2**90, 2**90), + (2**100, 2**100), ], ) def test_convert_size_string_to_bytes_and_convert_size_bytes_to_string(