Skip to content

fix: resolve IndexError in decompress_list for empty input#3031

Open
Vansh0204 wants to merge 8 commits intoNetflix:masterfrom
Vansh0204:fix/3017-decompress-list-indexerror
Open

fix: resolve IndexError in decompress_list for empty input#3031
Vansh0204 wants to merge 8 commits intoNetflix:masterfrom
Vansh0204:fix/3017-decompress-list-indexerror

Conversation

@Vansh0204
Copy link
Copy Markdown
Contributor

Fix: resolve IndexError in decompress_list for empty input

Fixes #3017

Problem

The decompress_list function was not guarding against empty string input. Since compress_list([]) legitimately returns an empty string "", calling decompress_list(compress_list([])) would immediately crash with:
IndexError: string index out of range at line 387 (if lststr[0] == zlibmarker:).

Fix

Added an early return guard if not lststr: return [] in decompress_list.

Change

  • File: metaflow/util.py
  • Added check to return [] if input string is empty.

Verification

Verified with a round-trip test:
decompress_list(compress_list([])) now correctly returns [] instead of raising an IndexError.

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-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 13, 2026

Greptile Summary

This PR fixes the IndexError crash in decompress_list when passed an empty string (the output of compress_list([])) by adding a precise if lststr == "" guard. It also adds comprehensive tests covering all three compression modes and explicitly documents the pre-existing [""] encoding ambiguity. All prior review thread concerns have been addressed.

Confidence Score: 5/5

Safe to merge — the fix is minimal, precise, and well-tested.

The guard is correctly narrowed to lststr == "" (not the broader not lststr), the known encoding ambiguity is documented in both code and tests, and all three compression modes have round-trip coverage. All concerns raised in prior review threads have been addressed.

No files require special attention.

Important Files Changed

Filename Overview
metaflow/util.py Adds a precise if lststr == "" guard in decompress_list to fix IndexError on empty input, with a clear comment documenting the compress_list([""]) ambiguity.
test/unit/test_util.py New test file covering all three decompression modes (plain CSV, prefix-encoded, zlib), the fixed empty-string edge case, and an explicit test documenting the known compress_list([""]) data-loss limitation.

Reviews (7): Last reviewed commit: "Merge branch 'master' into fix/3017-deco..." | Re-trigger Greptile

Comment thread metaflow/util.py Outdated
- Update decompress_list to check specifically for "" as a guard.
- Add test/unit/test_util.py with regression tests for empty input.
Comment thread test/unit/test_util.py
Comment thread metaflow/util.py
- 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 [""].
Comment thread test/unit/test_util.py
Comment thread test/unit/test_util.py
- Remove fragile internal assertion
- Explicitly assert the known data loss issue when round-tripping
Comment thread test/unit/test_util.py Outdated
Comment thread test/unit/test_util.py Outdated
- 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
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.

bug: decompress_list raises IndexError on empty string input

1 participant