Skip to content

fix: bound tar.gz metadata decompression - #5179

Open
mnriem wants to merge 2 commits into
github:mainfrom
mnriem:mnriem-archive-metadata-limits
Open

mnriem wants to merge 2 commits into
github:mainfrom
mnriem:mnriem-archive-metadata-limits

Conversation

@mnriem

@mnriem mnriem commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Description

Bound decompressed tar.gz reads and seeks before GNU/PAX metadata parsing in both archive format detection and extraction. The shared 54 MiB stream limit includes headers, padding, metadata, and file contents while preserving the existing member-size and total-file-size limits.

Report limit violations through the caller's error type, preserve caller-owned streams, and document the limit in the shared catalog reference.

Testing

  • Tested locally with uv run specify --help
  • Ran existing tests with uv sync && uv run pytest
  • Tested with a sample project (if applicable)

The full suite used the documented worktree-local interpreter instead of the template's uv run pytest invocation:

  • LC_ALL=en_US.UTF-8 .venv/bin/python -m pytest tests -n 4 -q --tb=short — passed: 13,691 passed, 130 skipped, 63 warnings.
  • uv run specify --help — passed.

A separate sample project is not applicable to this shared archive-helper change.

AI Disclosure

  • I did not use AI assistance for this contribution
  • I did use AI assistance (fill in the disclosure below)

AI disclosure: GitHub Copilot using GPT-6.1 Sol performed autonomous, user-directed implementation and validation and generated the code, tests, documentation, and PR description. Reasoning effort was not exposed to the session. A GitHub Copilot security-review subagent assisted with the initial assessment; its model was not reported. No line-by-line human review is claimed.

Enforce a shared decompressed-stream limit before tar metadata reads and forward seeks in archive detection and extraction.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI auto review requested due to automatic review settings October 29, 2026 14:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Tiny archives can trigger excessive memory use without a dedicated GNU/PAX metadata limit, while exception-handling flaws can reject valid ZIPs and obscure format-mismatch and size-limit diagnostics.

3 open issues
What changed in this PR

Hardens Spec Kit’s shared archive helpers by bounding decompressed tar.gz access before GNU/PAX metadata parsing during format detection and extraction.

Changes:

  • Adds a 54 MiB decompressed-stream budget alongside existing member and total-file-size limits.
  • Adds coverage for oversized metadata, read/seek boundaries, and caller-owned stream handling.
  • Documents the stream limit in the shared catalog reference.

AI disclosure: GitHub Copilot performed this review autonomously for the requester; model/settings unavailable. Review text and suggested fixes are AI-generated.

File Description
tests/​test_download_security.py Adds metadata-budget, stream-boundary, and stream-ownership coverage.
src/​specify_cli/​_download_security.py Adds a bounded gzip reader for tar detection and extraction.
docs/​reference/​catalogs.md Documents the 54 MiB limit and its scope.

Review effort: Max (auto)

Comment thread src/specify_cli/_download_security.py
Comment thread src/specify_cli/_download_security.py Outdated
Comment thread src/specify_cli/_download_security.py Outdated
@mnriem mnriem added the triage-must-have Verdict: high-value, important work for Spec Kit — do first label Oct 29, 2026
Bound individual GNU/PAX payloads before recursive metadata parsing, preserve size-limit errors for OSError-derived caller types, and treat malformed gzip headers as format-probe failures.

Assisted-by: GitHub Copilot (model: GPT-6.1 Sol, autonomous)
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI auto review requested due to automatic review settings October 29, 2026 16:26
@mnriem

mnriem commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed commit 373ca76: GNU/PAX metadata payloads are now capped at 64 KiB before recursive parsing reads them, size-limit diagnostics are preserved for OSError-derived caller errors, and malformed gzip headers no longer hide format mismatches or reject otherwise valid ZIP archives. The targeted archive and installer suites passed all 1,791 tests. AI disclosure: posted on behalf of @mnriem by GitHub Copilot using GPT-6.1 Sol in autonomous, user-directed mode; reasoning effort was not exposed. The code, tests, documentation, and this summary were AI-generated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

GNU sparse maps bypass the metadata cap and allow large in-memory lists, while extension and workflow wrappers conceal archive-limit errors.

2 open issues
3 resolved since last review

Review effort: Max (auto)



class _BoundedTarInfo(tarfile.TarInfo):
"""Check every metadata header, including headers parsed recursively."""
Comment on lines +253 to +254
except _TarLimitError as exc:
_raise_from(error_type, str(exc), exc)

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

triage-must-have Verdict: high-value, important work for Spec Kit — do first

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants