feat: close campaign findings by code review

campaign.py review applies or rejects an open finding with the reason read in the code. Applied fields go through the profile editor with the finding's records as evidence. The rule table reads on_mismatch: warn and counts a signature as a content check.
This commit is contained in:
Abdessamad Derraz committed 2026-10-28 08:16:27 +01:00
1 parent 7259dbc7c4
commit 48f5dbc813
5 files changed
+175 -6

No files matched your search

+18 -4
View File
@@ -28,7 +28,9 @@ name (zeros of its size, its first half, another region's dump).
core reports a BIOS error, or when it boots without the BIOS screens the
right file shows (it fell back to a built-in BIOS). It is used when it
turns the run into a hang or a crash that the run without any file does not
show. Anything else settles nothing. Of validation, the table writes only a
show. Anything else settles nothing. A check the entry declares with
`on_mismatch: warn` is one the code only logs: a wrong file that runs
agrees with it. Of validation, the table writes only a
missing `size`. A contradicted content check goes to review: which hash a
core computes is read in its code.
@@ -48,7 +50,7 @@ UNKNOWN = "unknown"
FAILS = (BIOS_ERROR, CRASH, HANG)
REFUSED = "refused"
USED = "used"
CONTENT_CHECKS = ("md5", "sha1", "sha256", "crc32", "adler32")
CONTENT_CHECKS = ("md5", "sha1", "sha256", "crc32", "adler32", "signature")
# A field an entry leaves out reads as this value.
FIELD_DEFAULTS: dict[str, object] = {"hle_fallback": False, "path": None, "aliases": [],
@@ -185,6 +187,17 @@ def declared_checks(entry: dict) -> tuple[set[str], bool]:
return {str(v) for v in value}, True
def warned_checks(entry: dict, checks: set[str]) -> set[str]:
"""The declared checks whose failure the code only logs (`on_mismatch:
warn`, for all of them or check by check): a wrong file still runs."""
level = entry.get("on_mismatch")
if level == "warn":
return set(checks)
if isinstance(level, dict):
return {check for check, value in level.items() if value == "warn"} & checks
return set()
def rule_validation(zeros: Run | None, half: Run | None, none: Run, present: Run,
entry: dict) -> Verdict | None:
"""Same-size and short wrong files against the right one: validation."""
@@ -199,19 +212,20 @@ def rule_validation(zeros: Run | None, half: Run | None, none: Run, present: Run
if content is None and size is None:
return None
declared, editable = declared_checks(entry)
enforced = declared - warned_checks(entry, declared)
evidence = ids(*(run for run in (none, present, zeros, half) if run))
said = sorted(declared)
shown = []
problems = []
if content is not None:
shown.append("checks the content" if content else "does not check the content")
if content != bool(declared & set(CONTENT_CHECKS)):
if content != bool(enforced & set(CONTENT_CHECKS)):
problems.append("a same-size file of zeros is " + ("refused" if content else "run")
+ f", the profile declares validation {said}")
missing_size = size is True and "size" not in declared
if size is not None:
shown.append("checks the size" if size else "does not check the size")
if size is False and "size" in declared:
if size is False and "size" in enforced:
problems.append(f"the first half of {name} is run, the profile declares a size check")
statement = f"the core {' and '.join(shown)} of {name}"
# What the runs show, for a finding beside what the profile says.