Skip to content

Fix unintended prefix matches in archive member selection - #557

Open
mikegit123git wants to merge 2 commits into
fatiando:mainfrom
mikegit123git:fix-archive-member-selection
Open

mikegit123git wants to merge 2 commits into
fatiando:mainfrom
mikegit123git:fix-archive-member-selection

Conversation

@mikegit123git

Copy link
Copy Markdown

Summary

Fix unintended prefix matches when extracting selected archive members using Unzip and Untar.

Previously, selecting a directory such as selected could also extract unrelated entries like selected-extra/file.txt or selectedfile.txt.

Similarly, selecting an exact file such as selected/ok.txt could unintentionally include selected/ok.txt.bak.

This happens because the current implementation uses startswith() without checking path-component boundaries.

Changes

  • Introduce a shared _is_selected_member() helper to match exact archive members or descendants of selected directories.
  • Apply the boundary-aware matching logic consistently to ZIP and TAR extraction.
  • Update ExtractorProcessor to filter returned file paths using the same matching logic.
  • Add 20 parameterized regression tests covering ZIP and TAR archives, exact file selection, directory selection, trailing slashes, multiple selected members, and existing extraction directories.

The fix is focused on archive member matching and does not modify the underlying extraction or cache management routines.

Verification

The same 20 regression tests were executed against both the original and patched source.

  • Original: 8 passed, 12 failed.
  • Patched: 20 passed, 0 failed.

All 12 previously failing tests pass after applying the fix.

Additional local verification

  • 24 compatibility scenarios passed across ZIP, TAR, and TAR.GZ archives.
  • Cache transition checks passed for all three archive formats, including partial extraction, full extraction, and subsequent selection from an existing cache.
  • POSIX and Windows path-matching logic checks passed in a Linux environment.
  • Offline test suite: 82 passed, 13 skipped, 85 deselected.
  • Targeted Ruff checks passed with two pre-existing FLY002 warnings excluded.
  • Ruff formatting checks passed.
  • Git whitespace checks passed.

These checks confirm that the patch prevents unintended prefix matches while preserving the extraction and caching behaviors covered by the tests.

Cross-platform CI verification is still pending.

Related issue

Closes #556

This branch has not been deployed

No deployments
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.

Unzip and Untar incorrectly extract archive members with matching name prefixes

1 participant