Skip to content

fix: harden GGUF/ZIP polyglot detection#1775

Merged
mldangelo-oai merged 14 commits into
mainfrom
mdangelo/codex/fix-gguf-polyglot-hardening-20260721
Jul 22, 2026
Merged

fix: harden GGUF/ZIP polyglot detection#1775
mldangelo-oai merged 14 commits into
mainfrom
mdangelo/codex/fix-gguf-polyglot-hardening-20260721

Conversation

@mldangelo-oai

Copy link
Copy Markdown
Contributor

Summary

  • Compute the declared GGUF payload boundary for both empty and populated tensor tables, while allowing only bounded zero padding.
  • Detect genuine GGUF/ZIP polyglots with the existing S908 rule and reuse the existing ZIP/archive dispatch to inspect hidden pickle, path-traversal, and nested content.
  • Preserve scanner-selection policy, benign Llamafile container boundaries, and existing fail-closed/incomplete-coverage exit semantics.
  • Add focused regressions for zero-tensor files, file-controlled alignment, malformed ZIP lookalikes, bounded padding, forged provenance flags, nested malicious pickles, archive traversal, and CLI enforcement.

Why

GGUF parsers can legitimately stop after the declared tensor payload while ZIP readers recognize a valid archive from the same file's end. This change improves format identification and defense in depth by recognizing both interpretations and delegating archive inspection to the scanner infrastructure that already enforces extraction and recursion limits.

Validation

  • PROMPTFOO_DISABLE_TELEMETRY=1 pytest tests/scanners/test_gguf_scanner.py tests/scanners/test_llamafile_scanner.py tests/scanners/test_zip_scanner.py tests/test_gguf_sbom_integration.py -n 4 -m "not slow and not integration" --maxfail=2 -q1,664 passed.
  • ruff format --check modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/ — passed.
  • ruff check modelaudit/ packages/modelaudit-picklescan/src packages/modelaudit-picklescan/tests tests/ — passed.
  • mypy modelaudit/scanners/gguf_scanner.py modelaudit/scanners/llamafile_scanner.py tests/scanners/test_gguf_scanner.py — passed.

The complete local suite cannot collect in the existing environment because the optional compiled modelaudit_picklescan._rust extension is absent; CI builds the native extension.

Thanks

Thank you to @mgm-77 for the thoughtful report and clear proof of concept that inspired this defense-in-depth improvement.

Copilot AI review requested due to automatic review settings July 22, 2026 02:02
@mldangelo-oai
mldangelo-oai marked this pull request as ready for review July 22, 2026 02:03

Copy link
Copy Markdown
Contributor Author

@codex review

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Workflow run and artifacts

Performance Benchmarks

Compared 13 shared benchmarks with a regression threshold of 15%.
Status: 0 regressions, 0 improved, 13 stable, 0 new, 0 missing.
Aggregate shared-benchmark median: 4.270s -> 4.266s (-0.1%).

Workload Benchmark Target Size Files Baseline Current Change Status
single-checkpoint-preflight tests/benchmarks/test_scan_benchmarks.py::test_scan_single_checkpoint_before_load single_checkpoint.pkl 183.0 KiB 1 102.50ms 105.51ms +2.9% stable
padded-multi-stream-upload tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_padded_multi_stream_upload multi_stream_padded 4.1 KiB 1 346.3us 336.7us -2.8% stable
direct-malicious-upload tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_direct_malicious_upload malicious_reduce 52 B 1 226.7us 223.3us -1.5% stable
nested-payload-review tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_nested_payload_review[nested_raw] nested_raw 78 B 1 275.9us 279.8us +1.4% stable
duplicate-heavy-registry tests/benchmarks/test_scan_benchmarks.py::test_scan_duplicate_registry_snapshot registry-snapshot 915.2 KiB 13 563.71ms 570.84ms +1.3% stable
nested-payload-review tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_nested_payload_review[nested_hex] nested_hex 130 B 1 310.9us 307.6us -1.0% stable
clean-training-checkpoint tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_clean_training_checkpoint safe_large 278.2 KiB 1 111.76ms 110.64ms -1.0% stable
nested-payload-review tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_nested_payload_review[nested_base64] nested_base64 98 B 1 298.2us 295.3us -1.0% stable
rejected-basic-auth-candidates tests/benchmarks/test_scan_benchmarks.py::test_rejected_basic_auth_candidates_scan_linearly - 371.1 KiB 1 2.452s 2.438s -0.6% stable
suspicious-pickle-intake tests/benchmarks/test_scan_benchmarks.py::test_scan_suspicious_pickle_intake suspicious-intake 183.8 KiB 4 147.85ms 148.63ms +0.5% stable
warm-cache-rescan tests/benchmarks/test_scan_benchmarks.py::test_scan_warm_cached_repository_rescan release-candidate 547.3 KiB 32 151.01ms 151.74ms +0.5% stable
chunked-upload-stream tests/benchmarks/test_picklescan_benchmarks.py::test_picklescan_chunked_upload_stream chunked_stream 278.2 KiB 1 114.38ms 114.13ms -0.2% stable
mixed-model-repository tests/benchmarks/test_scan_benchmarks.py::test_scan_release_candidate_repository release-candidate 547.3 KiB 32 624.71ms 625.72ms +0.2% stable

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.

Pull request overview

This PR hardens GGUF scanning by computing a “declared content boundary” and flagging/inspecting unexplained trailing bytes, including detecting GGUF/ZIP polyglots and delegating ZIP member inspection to the existing archive dispatch pipeline (so hidden pickles/path traversal/nested content are covered consistently).

Changes:

  • Compute a GGUF logical end offset (including the final tensor payload) and validate/flag trailing content with bounded zero-padding tolerance.
  • Detect GGUF/ZIP polyglots (S908) and reuse merge_executable_zip_container_findings to scan embedded archive members.
  • Propagate a trusted “container-owned trailing boundary” marker for GGUF payloads carved from Llamafile containers, and add targeted regression coverage.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
tests/scanners/test_gguf_scanner.py Adds regression tests for GGUF trailing bytes, bounded padding, ZIP polyglots, archive traversal, and scanner-selection/CLI behavior.
modelaudit/scanners/llamafile_scanner.py Marks carved GGUF payloads as container-owned for trailing-boundary validation and preserves ZIP polyglot merging behavior.
modelaudit/scanners/gguf_scanner.py Implements trailing-content validation and GGUF/ZIP polyglot detection + archive dispatch integration.
CHANGELOG.md Documents the GGUF/ZIP polyglot and trailing-content validation hardening under Unreleased bug fixes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread modelaudit/scanners/gguf_scanner.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9bb572c90e

ℹ️ 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".

Comment thread modelaudit/scanners/gguf_scanner.py Outdated
Comment thread modelaudit/scanners/llamafile_scanner.py Outdated
Comment thread modelaudit/scanners/llamafile_scanner.py Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 02:31

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f170d70fe4

ℹ️ 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".

Comment thread modelaudit/scanners/gguf_scanner.py
Comment thread modelaudit/scanners/llamafile_scanner.py Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 02:42

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread modelaudit/scanners/gguf_scanner.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d1d286e4a5

ℹ️ 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".

Comment thread modelaudit/scanners/llamafile_scanner.py Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 03:00

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread modelaudit/scanners/gguf_scanner.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d54ef005f8

ℹ️ 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".

Comment thread modelaudit/scanners/gguf_scanner.py
Copilot AI review requested due to automatic review settings July 22, 2026 03:11

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4ebcb2976

ℹ️ 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".

Comment thread modelaudit/scanners/gguf_scanner.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 105b78415d

ℹ️ 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".

Comment thread modelaudit/scanners/llamafile_scanner.py Outdated
Comment thread modelaudit/scanners/llamafile_scanner.py Outdated
Comment thread modelaudit/scanners/llamafile_scanner.py
Copilot AI review requested due to automatic review settings July 22, 2026 04:15

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a621269c70

ℹ️ 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".

Comment thread modelaudit/scanners/gguf_scanner.py Outdated

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread modelaudit/scanners/llamafile_scanner.py Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 04:37

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread modelaudit/scanners/gguf_scanner.py
Copilot AI review requested due to automatic review settings July 22, 2026 04:43

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a72134e5a7

ℹ️ 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".

Comment thread modelaudit/scanners/gguf_scanner.py Outdated
Comment thread modelaudit/scanners/llamafile_scanner.py Outdated
Comment thread modelaudit/scanners/llamafile_scanner.py Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 04:59

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 22, 2026 05:38

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment thread modelaudit/scanners/gguf_scanner.py
Copilot AI review requested due to automatic review settings July 22, 2026 05:48

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.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

modelaudit/scanners/gguf_scanner.py:769

  • _scan_zip_polyglot() calls zipfile.is_zipfile() and then immediately calls merge_executable_zip_container_findings(), which performs its own is_zipfile probe. This results in redundant file opens/reads on every GGUF scan.

You can drop the direct is_zipfile call and instead gate S908 emission on whether merge_executable_zip_container_findings() actually dispatched for this path (it records the path in private metadata), while still honoring the existing preflight-rejected path marker.

        if not zipfile.is_zipfile(self.current_file_path):
            return False

        from .archive_dispatch import (
            _ZIP_CONTAINER_PREFLIGHT_REJECTED_PATHS_PRIVATE_METADATA_KEY,

@mldangelo-oai
mldangelo-oai merged commit 665ed3a into main Jul 22, 2026
32 checks passed
@mldangelo-oai
mldangelo-oai deleted the mdangelo/codex/fix-gguf-polyglot-hardening-20260721 branch July 22, 2026 06:31
@github-actions github-actions Bot mentioned this pull request Jul 22, 2026
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.

2 participants