diff --git a/tools/public_release/check_public_tree.py b/tools/public_release/check_public_tree.py index b029b04..2ef2d4b 100644 --- a/tools/public_release/check_public_tree.py +++ b/tools/public_release/check_public_tree.py @@ -7,6 +7,7 @@ from __future__ import annotations import argparse import dataclasses +import hashlib import json from pathlib import Path, PurePosixPath import re @@ -26,7 +27,7 @@ ASSET_SUFFIXES = { ".fbm", ".vga", ".blk", ".col", ".lbm", ".fnt", ".wap", ".ein", ".men", ".dat", ".exe", ".dll", ".so", ".dylib", ".wav", ".mp3", ".ogg", ".flac", ".avi", ".mov", ".mp4", ".png", ".jpg", ".jpeg", ".bmp", ".gif", - ".bin", ".zip", ".7z", ".dmg", ".tar", ".gz", ".pdf", + ".bin", ".zip", ".7z", ".dmg", ".tar", ".gz", ".pdf", ".tga", } PRIVATE_PREFIXES = ( ("data", "original"), ("docs", "manuals"), ("docs", "analyses"), @@ -40,6 +41,15 @@ PRIVATE_DOCUMENTS = { } SOURCE_SUFFIXES = {".cpp", ".hpp", ".h", ".c", ".inc"} SKIP_DIRECTORIES = {".git", "__pycache__", ".cache", "_deps", "node_modules"} +# Independently generated launcher artwork already published on the launcher +# branch, with provenance in its assets/launcher/provenance.json. History checks +# include those branches too. Approve only these exact reviewed bytes and path. +PROJECT_ARTWORK = { + "assets/launcher/stadium.tga": { + "08f82783a357d5b0722f3737de54844150bc14d98036845f1aaee3211608e1c8", + "fb8e5f1f86afe60de87b70a2f533690d1ef470241fa24ee4384ff000149edaab", + }, +} LEGACY_SYMBOLS = re.compile( r"(? list[Finding]: result = [] if path.is_absolute() or ".." in parts: result.append(Finding(name, 0, "unsafe-path")) - if path.suffix.lower() in ASSET_SUFFIXES: + if path.suffix.lower() in ASSET_SUFFIXES and name not in PROJECT_ARTWORK: result.append(Finding(name, 0, "binary-or-game-asset")) if path.name in PRIVATE_DOCUMENTS or any(parts[:len(p)] == p for p in PRIVATE_PREFIXES): result.append(Finding(name, 0, "private-material-path")) @@ -167,6 +177,10 @@ def path_findings(name: str) -> list[Finding]: def scan_blob(name: str, blob: bytes) -> list[Finding]: result = path_findings(name) + if name in PROJECT_ARTWORK: + if hashlib.sha256(blob).hexdigest() not in PROJECT_ARTWORK[name]: + result.append(Finding(name, 0, "unreviewed-project-artwork")) + return result if len(blob) > 2_000_000: result.append(Finding(name, 0, "oversized-source-file")) if b"\0" in blob: diff --git a/tools/public_release/test_public_tree.py b/tools/public_release/test_public_tree.py index cf589cb..3ef9d6e 100644 --- a/tools/public_release/test_public_tree.py +++ b/tools/public_release/test_public_tree.py @@ -4,6 +4,7 @@ """Synthetic checks for the source-distribution guard; no game input is used.""" import contextlib +import hashlib import io import json from pathlib import Path @@ -17,6 +18,22 @@ import check_public_tree as guard class BlobChecks(unittest.TestCase): + def test_only_exact_reviewed_project_artwork_is_accepted(self): + name = "assets/launcher/synthetic.tga" + payload = b"synthetic\0pixels" + with mock.patch.dict(guard.PROJECT_ARTWORK, {name: {hashlib.sha256(payload).hexdigest()}}): + self.assertEqual(guard.scan_blob(name, payload), []) + rules = {f.rule for f in guard.scan_blob(name, payload + b"changed")} + self.assertIn("unreviewed-project-artwork", rules) + self.assertIn("binary-or-game-asset", self.rules("assets/other.tga", "unreviewed")) + self.assertIn("binary-content", {f.rule for f in guard.scan_blob("other.tga", payload)}) + self.assertIn("binary-or-game-asset", self.rules(name, "unreviewed")) + + def test_public_edition_name_is_not_private_provenance(self): + edition = "DIA" + "MOND" + self.assertNotIn("private-provenance", self.rules("docs/ENGINE_SPLIT.md", "a later " + edition + " release")) + self.assertIn("private-provenance", self.rules("README.md", "/" + "tools/versions/" + edition)) + def rules(self, name, text): return {finding.rule for finding in guard.scan_blob(name, text.encode())}