root_sig_contract: reject unpaired ptr64_lo on 1-dword tables and harden console/input validation (ROOT-SIG-CONTRACT-CONSOLE-AND-VALIDATION) #1606

Merged
leonida/mandy
quietfold merged 1 commit from fix/root-sig-contract-console-and-validation into main 2026-11-28 10:35:37 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 05:45:56 +00:00

Item ID: ROOT-SIG-CONTRACT-CONSOLE-AND-VALIDATION (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches tools/root_sig_contract.py).

What changed

  • Reject ptr64_lo without a paired high dword (tools/root_sig_contract.py, reconcile): under --model console, descriptor tables occupy a single 32-bit dword (sub=0 only). Previously ptr64_lo without an explicit pair only checked slot["sub"] != 0, silently accepting a 64-bit pointer low-half read on a 1-dword console table (asymmetric with ptr64_hi and contradicting the explicit pair check). Now ptr64_lo requires dwords[sgpr + 1] to be sub=1 of the same root parameter.
  • Validate --rootsig on an empty index under --model console (main): previously an empty index.json ({}) looped over zero stages and exited 0 without ever calling pack_layout(sig, ...), accepting broken root signatures. Now an empty index still validates sig against the widest console stage (min(STAGE_BASE, key=STAGE_BASE.get) -> cs, base s4), refusing malformed/oversized signatures while keeping valid console signatures accepted.
  • Reject missing or non-string stage under --model console (main): exit 2 with a clear ERROR: on stderr instead of stringifying None/ints into "None"/"4" and reporting a root-signature refusal.
  • Guard unhashable stage / kind values (pack_layout, reconcile, cluster): avoid TypeError: unhashable type when called programmatically with non-string stage or kind values.
  • Support UTF-8 BOM inputs and reject whitespace-only CLI paths (_load_json, main): open JSON inputs with utf-8-sig and reject whitespace-only index/--rootsig arguments with a usage error.
  • Synthetic regression tests (tests/test_root_sig_contract_edges.py): 7 new tests covering all of the above (no game files, no GPU).

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU-only Python tool on macOS)
  • python3 -W error -I tests/test_root_sig_contract_edges.py -v: 13 passed
  • python3 -W error -m pytest tests/test_root_sig_contract.py -v: 58 passed
  • python3 -W error -I tests/test_text_write_line_endings.py: passed
  • python3 -I scripts/check_no_game_data.py tools/root_sig_contract.py tests/test_root_sig_contract_edges.py: clean
  • python3 -m compileall -q tools/root_sig_contract.py tests/test_root_sig_contract_edges.py: clean
  • Mutation test (tests/test_root_sig_contract_edges.py against unpatched main:tools/root_sig_contract.py): 10 failures, 5 errors across the 13 tests (all new tests fail on unpatched main).
Item ID: `ROOT-SIG-CONTRACT-CONSOLE-AND-VALIDATION` (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches `tools/root_sig_contract.py`). ## What changed - **Reject `ptr64_lo` without a paired high dword (`tools/root_sig_contract.py`, `reconcile`)**: under `--model console`, descriptor tables occupy a single 32-bit dword (`sub=0` only). Previously `ptr64_lo` without an explicit `pair` only checked `slot["sub"] != 0`, silently accepting a 64-bit pointer low-half read on a 1-dword console table (asymmetric with `ptr64_hi` and contradicting the explicit `pair` check). Now `ptr64_lo` requires `dwords[sgpr + 1]` to be `sub=1` of the same root parameter. - **Validate `--rootsig` on an empty index under `--model console` (`main`)**: previously an empty `index.json` (`{}`) looped over zero stages and exited `0` without ever calling `pack_layout(sig, ...)`, accepting broken root signatures. Now an empty index still validates `sig` against the widest console stage (`min(STAGE_BASE, key=STAGE_BASE.get)` -> `cs`, base `s4`), refusing malformed/oversized signatures while keeping valid console signatures accepted. - **Reject missing or non-string `stage` under `--model console` (`main`)**: exit `2` with a clear `ERROR:` on stderr instead of stringifying `None`/ints into `"None"`/`"4"` and reporting a root-signature refusal. - **Guard unhashable `stage` / `kind` values (`pack_layout`, `reconcile`, `cluster`)**: avoid `TypeError: unhashable type` when called programmatically with non-string `stage` or `kind` values. - **Support UTF-8 BOM inputs and reject whitespace-only CLI paths (`_load_json`, `main`)**: open JSON inputs with `utf-8-sig` and reject whitespace-only `index`/`--rootsig` arguments with a usage error. - **Synthetic regression tests (`tests/test_root_sig_contract_edges.py`)**: 7 new tests covering all of the above (no game files, no GPU). ## Verification - AI-assisted: yes - GPUs tested: none (CPU-only Python tool on macOS) - `python3 -W error -I tests/test_root_sig_contract_edges.py -v`: **13 passed** - `python3 -W error -m pytest tests/test_root_sig_contract.py -v`: **58 passed** - `python3 -W error -I tests/test_text_write_line_endings.py`: passed - `python3 -I scripts/check_no_game_data.py tools/root_sig_contract.py tests/test_root_sig_contract_edges.py`: clean - `python3 -m compileall -q tools/root_sig_contract.py tests/test_root_sig_contract_edges.py`: clean - Mutation test (`tests/test_root_sig_contract_edges.py` against unpatched `main:tools/root_sig_contract.py`): **10 failures, 5 errors** across the 13 tests (all new tests fail on unpatched `main`).
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 05:46:08 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:35:29 +00:00

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.