The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(plugin-catalog): rule 17 gate reads a single gzipped file instead of failing it
teknium10a711e141b52
diff --git a/scripts/scan_plugin_payloads.py b/scripts/scan_plugin_payloads.pyindex d67e8bf20e9..f3894f7dafa 100755--- a/scripts/scan_plugin_payloads.py+++ b/scripts/scan_plugin_payloads.py@@ -22,7 +22,10 @@ Exit 0 = clean, 1 = a payload was found (lines on stdout), 2 = bad usage."""from __future__ import annotations+import bz2+import gzipimport io+import lzmaimport osimport subprocessimport sys@@ -105,6 +108,8 @@ def _archive_problem(path: Path, data: bytes) -> str | None:if fobj is not None and _magic_kind(fobj.read(8)):return f"archive member is a compiled binary: {member.name}"return None+ except tarfile.ReadError:+ return _single_stream_problem(path, data)except (tarfile.TarError, zipfile.BadZipFile, OSError, EOFError):# Not a parseable archive we recognise. A file carrying an archive# suffix we cannot open is itself unreviewable.@@ -112,6 +117,28 @@ def _archive_problem(path: Path, data: bytes) -> str | None:return "archive could not be opened for review"+_SINGLE_STREAM = {".gz": gzip.open, ".bz2": bz2.open, ".xz": lzma.open}+++def _single_stream_problem(path: Path, data: bytes) -> str | None:+ """A compressed single file (``words.tsv.gz``) is reviewable when the name it+ decompresses to is source and its content is not a compiled binary."""+ opener = _SINGLE_STREAM.get(path.suffix.lower())+ if opener is None:+ return "archive could not be opened for review"+ inner = path.name[: -len(path.suffix)]+ try:+ with opener(io.BytesIO(data)) as stream:+ head = stream.read(8)+ except (OSError, EOFError, lzma.LZMAError):+ return "archive could not be opened for review"+ if not _is_source_member(inner):+ return f"compressed file is not reviewable source: {inner}"+ if _magic_kind(head):+ return f"compressed file is a compiled binary: {inner}"+ return None++def _file_problem(path: Path, rel: str) -> str | None:"""Return a rule-17 reason this single file is unreviewable, or None."""if path.suffix.lower() in _BYTECODE_SUFFIXES:diff --git a/tests/scripts/test_scan_plugin_payloads.py b/tests/scripts/test_scan_plugin_payloads.pyindex aabcf3fd114..64d8c2a121b 100644--- a/tests/scripts/test_scan_plugin_payloads.py+++ b/tests/scripts/test_scan_plugin_payloads.py@@ -94,6 +94,18 @@ def test_tarball_with_unknown_blob_member_fails(tmp_path):assert any("not reviewable source" in f for f in findings), findings[email protected]("name, body, expect", [+ ("words.tsv.gz", b"haus\thaeuser\n", None), # gzipped text data: reviewable+ ("tool.py.gz", b"\x7fELF" + b"\x00" * 40, "compiled binary"), # ELF under a source name+ ("payload.bin.gz", b"opaque", "not reviewable source"),+])+def test_single_compressed_file_is_judged_by_what_it_decompresses_to(tmp_path, name, body, expect):+ import gzip+ (tmp_path / name).write_bytes(gzip.compress(body))+ findings = _scan(tmp_path)+ assert (findings == []) if expect is None else any(expect in f for f in findings), findings++def test_zip_hiding_a_binary_fails(tmp_path):arc = tmp_path / "bundle.zip"with zipfile.ZipFile(arc, "w") as zf: