fix: resolve IndexError in decompress_list for empty input#3031
Open
Vansh0204 wants to merge 7 commits intoNetflix:masterfrom
Open
fix: resolve IndexError in decompress_list for empty input#3031Vansh0204 wants to merge 7 commits intoNetflix:masterfrom
Vansh0204 wants to merge 7 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
Contributor
Greptile SummaryThis PR fixes a crash in
Confidence Score: 5/5
Important Files Changed
Last reviewed commit: f399208 |
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.