Fix source export history checks (by Codex)

Fix public-source checks across launcher history
This commit is contained in:
Michael authored and GitHub committed 2026-10-22 12:12:03 +02:00
commit b868a236ea
2 files changed
+35 -4

No files matched your search

+18 -4
View File
@@ -7,6 +7,7 @@ from __future__ import annotations
import argparse import argparse
import dataclasses import dataclasses
import hashlib
import json import json
from pathlib import Path, PurePosixPath from pathlib import Path, PurePosixPath
import re import re
@@ -26,7 +27,7 @@ ASSET_SUFFIXES = {
".fbm", ".vga", ".blk", ".col", ".lbm", ".fnt", ".wap", ".ein", ".men", ".dat", ".fbm", ".vga", ".blk", ".col", ".lbm", ".fnt", ".wap", ".ein", ".men", ".dat",
".exe", ".dll", ".so", ".dylib", ".wav", ".mp3", ".ogg", ".flac", ".exe", ".dll", ".so", ".dylib", ".wav", ".mp3", ".ogg", ".flac",
".avi", ".mov", ".mp4", ".png", ".jpg", ".jpeg", ".bmp", ".gif", ".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 = ( PRIVATE_PREFIXES = (
("data", "original"), ("docs", "manuals"), ("docs", "analyses"), ("data", "original"), ("docs", "manuals"), ("docs", "analyses"),
@@ -40,6 +41,15 @@ PRIVATE_DOCUMENTS = {
} }
SOURCE_SUFFIXES = {".cpp", ".hpp", ".h", ".c", ".inc"} SOURCE_SUFFIXES = {".cpp", ".hpp", ".h", ".c", ".inc"}
SKIP_DIRECTORIES = {".git", "__pycache__", ".cache", "_deps", "node_modules"} 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( LEGACY_SYMBOLS = re.compile(
r"(?<![A-Za-z0-9])(?:" + "FUN" + r"_?[0-9a-f]{4,8}|" + "DAT" + r"(?<![A-Za-z0-9])(?:" + "FUN" + r"_?[0-9a-f]{4,8}|" + "DAT" +
@@ -50,8 +60,8 @@ LEGACY_SYMBOLS = re.compile(
PRIVATE_TEXT = re.compile( PRIVATE_TEXT = re.compile(
r"(?:(?<![\w}./\\])/" + r"tools/|[A-Z]:[/\\]Users[/\\]|[A-Z]:[/\\]OpenBMH[/\\]|" r"(?:(?<![\w}./\\])/" + r"tools/|[A-Z]:[/\\]Users[/\\]|[A-Z]:[/\\]OpenBMH[/\\]|"
r"docs/(?:analyses|agents)/|src/ui/(?:validation|reference)/|" r"docs/(?:analyses|agents)/|src/ui/(?:validation|reference)/|"
+ "bmh" + r"-work|matter" + r"most|\bMich" + r"ael\b|\bDIA" + + "bmh" + r"-work|matter" + r"most|\bMich" + r"ael\b|"
r"MOND\b|(?<![\w}./\\])/" + r"root/[^\s]+|https?://(?:10\.|192\.168\.|172\.(?:1[6-9]|2[0-9]|3[01])\.)|" r"(?<![\w}./\\])/" + r"root/[^\s]+|https?://(?:10\.|192\.168\.|172\.(?:1[6-9]|2[0-9]|3[01])\.)|"
r"github\.com/[^/\s]+/openbmh[_-]dc\b)", r"github\.com/[^/\s]+/openbmh[_-]dc\b)",
re.IGNORECASE, re.IGNORECASE,
) )
@@ -156,7 +166,7 @@ def path_findings(name: str) -> list[Finding]:
result = [] result = []
if path.is_absolute() or ".." in parts: if path.is_absolute() or ".." in parts:
result.append(Finding(name, 0, "unsafe-path")) 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")) 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): 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")) 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]: def scan_blob(name: str, blob: bytes) -> list[Finding]:
result = path_findings(name) 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: if len(blob) > 2_000_000:
result.append(Finding(name, 0, "oversized-source-file")) result.append(Finding(name, 0, "oversized-source-file"))
if b"\0" in blob: if b"\0" in blob:
+17
View File
@@ -4,6 +4,7 @@
"""Synthetic checks for the source-distribution guard; no game input is used.""" """Synthetic checks for the source-distribution guard; no game input is used."""
import contextlib import contextlib
import hashlib
import io import io
import json import json
from pathlib import Path from pathlib import Path
@@ -17,6 +18,22 @@ import check_public_tree as guard
class BlobChecks(unittest.TestCase): 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): def rules(self, name, text):
return {finding.rule for finding in guard.scan_blob(name, text.encode())} return {finding.rule for finding in guard.scan_blob(name, text.encode())}