-
Notifications
You must be signed in to change notification settings - Fork 16
fix(ggml): detect embedded ZIP polyglot payloads #1780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -760,8 +760,8 @@ def _scan_gguf(self, f: BinaryIO, file_size: int, result: ScanResult) -> None: | |
| ) | ||
| result.bytes_scanned = max(result.bytes_scanned, f.tell()) | ||
|
|
||
| def _scan_zip_polyglot(self, result: ScanResult) -> bool: | ||
| """Inspect ZIP members even when GGUF metadata or tensor parsing fails.""" | ||
| def _scan_zip_polyglot(self, result: ScanResult, *, format_name: str = "GGUF") -> bool: | ||
| """Inspect ZIP members even when GGUF/GGML header parsing fails.""" | ||
| if not zipfile.is_zipfile(self.current_file_path): | ||
| return False | ||
|
|
||
|
|
@@ -776,7 +776,7 @@ def _scan_zip_polyglot(self, result: ScanResult) -> bool: | |
| self.current_file_path, | ||
| result, | ||
| archive_config, | ||
| context="GGUF trailing ZIP polyglot", | ||
| context=f"{format_name} trailing ZIP polyglot", | ||
| ) | ||
| rejected_paths = result._private_metadata.get( | ||
| _ZIP_CONTAINER_PREFLIGHT_REJECTED_PATHS_PRIVATE_METADATA_KEY, | ||
|
|
@@ -789,9 +789,9 @@ def _scan_zip_polyglot(self, result: ScanResult) -> bool: | |
| return False | ||
|
|
||
| result.add_check( | ||
| name="GGUF ZIP Polyglot Detection", | ||
| name=f"{format_name} ZIP Polyglot Detection", | ||
| passed=False, | ||
| message="GGUF file is also a valid ZIP archive and may contain hidden archive content", | ||
| message=f"{format_name} file is also a valid ZIP archive and may contain hidden archive content", | ||
| severity=IssueSeverity.CRITICAL, | ||
| location=self.current_file_path, | ||
| details={"embedded_format": "zip"}, | ||
|
|
@@ -1050,6 +1050,7 @@ def _scan_ggml( | |
| """Basic GGML file validation with security checks.""" | ||
| result.metadata["format"] = "ggml" | ||
| result.metadata["magic"] = magic.decode("ascii", "ignore") | ||
| self._scan_zip_polyglot(result, format_name="GGML") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a ZIP member is itself a GGUF/GGML model, Useful? React with 👍 / 👎. |
||
|
|
||
| if file_size < 32: | ||
| result.add_check( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a compressed ZIP member expands beyond the outer file size, this call merges the member scan's
bytes_scanned, but_scan_ggmllater replaces it withfile_size. In a directory containing several GGML polyglots whose individual uncompressed totals are belowmax_total_size, aggregate accounting can therefore remain below--max-sizeand continue scanning past the safety budget; retain at least the merged count, as_scan_ggufdoes, and cover this budget outcome.AGENTS.md reference: AGENTS.md:L137-L137
Useful? React with 👍 / 👎.