fix: route PyTorch ZIP archives without metadata#1016
Conversation
Performance BenchmarksCompared Top improvements:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2bbc973641
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| def _looks_like_pytorch_zip_storage_members(member_names: set[str], prefix: str) -> bool: | ||
| """Detect PyTorch tensor storage members next to data.pkl.""" | ||
| storage_prefix = f"{prefix}/data/" if prefix else "data/" | ||
| return any(name.startswith(storage_prefix) and name != storage_prefix for name in member_names) |
There was a problem hiding this comment.
Restrict storage-member match before PyTorch routing
_looks_like_pytorch_zip_storage_members treats any file under <prefix>/data/ as tensor storage. A generic ZIP containing data.pkl plus data/readme.txt now routes to pytorch_zip, even when it is not a PyTorch archive. That scanner does not do generic ZIP recursive dispatch, so this broad match can reduce coverage (e.g., nested archive threats) compared with ZipScanner.
Useful? React with 👍 / 👎.
Summary
Route ZIP-backed PyTorch archives to the PyTorch ZIP scanner when they contain
data.pklplus PyTorch tensor storage members, even ifversionandbyteordermetadata entries are missing.Security impact
Previously, a torch-loadable ZIP with
data.pkland storage entries but no metadata could fall through to the generic ZIP scanner when the suffix was misleading. That skipped PyTorch-specific CVE checks and pickle handling paths. The new fallback still requires storage members next todata.pkl, so a generic ZIP containing onlydata.pklremains routed to the generic ZIP scanner.Validation
uv run ruff format modelaudit/utils/file/detection.py tests/test_core.pyPROMPTFOO_DISABLE_TELEMETRY=1 uv run pytest tests/test_core.py tests/test_pytorch_zip_detection.py tests/scanners/test_pytorch_zip_scanner.py -quv run mypy modelaudit/utils/file/detection.py tests/test_core.py