fix: resolve IndexError in decompress_list for empty input#3031
fix: resolve IndexError in decompress_list for empty input#3031Vansh0204 wants to merge 8 commits intoNetflix:masterfrom
Conversation
compress_list([]) legitimately returns an empty string "".
However, decompress_list("") was attempting to access lststr[0]
without a guard, causing an IndexError.
This fix adds an early return for empty strings, ensuring that
decompress_list(compress_list([])) correctly returns [].
Fixes Netflix#3017
Greptile SummaryThis PR fixes the Confidence Score: 5/5Safe to merge — the fix is minimal, precise, and well-tested. The guard is correctly narrowed to No files require special attention. Important Files Changed
Reviews (7): Last reviewed commit: "Merge branch 'master' into fix/3017-deco..." | Re-trigger Greptile |
- Update decompress_list to check specifically for "" as a guard. - Add test/unit/test_util.py with regression tests for empty input.
- Add comment in decompress_list explaining the [] vs [""] ambiguity. - Expand test/unit/test_util.py with comprehensive round-trip tests for single-element, plain CSV, prefix-encoded, and zlib-compressed lists. - Add test documenting the known ambiguity between [] and [""].
- Remove fragile internal assertion - Explicitly assert the known data loss issue when round-tripping
- Update comment to clarify that the prefix encoding test is checking Mode 2 indirectly - Replace hardcoded '!' with ZLIB_MARKER in the zlib compression test to make the coupling visible
Fix: resolve IndexError in decompress_list for empty input
Fixes #3017
Problem
The
decompress_listfunction was not guarding against empty string input. Sincecompress_list([])legitimately returns an empty string"", callingdecompress_list(compress_list([]))would immediately crash with:IndexError: string index out of rangeat line 387 (if lststr[0] == zlibmarker:).Fix
Added an early return guard
if not lststr: return []indecompress_list.Change
metaflow/util.py[]if input string is empty.Verification
Verified with a round-trip test:
decompress_list(compress_list([]))now correctly returns[]instead of raising an IndexError.