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

Open
github-bot wants to merge 1 commit from github-bot/gh-1606 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 05:45 UTC · original
IlyassRS3:fix/root-sig-contract-console-and-validation → main · +143 −10 · 2 files · 1 commits · open

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).
**@⁠IlyassRS3** on GitHub · 2026-11-25 05:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1606) `IlyassRS3:fix/root-sig-contract-console-and-validation` → `main` · +143 −10 · 2 files · 1 commits · open 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`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:57:52 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 05:46 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 05:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1606#pullrequestreview-6052459440) · **reviewed** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1606/head:github-bot/gh-1606'
git switch 'github-bot/gh-1606'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1606'
git switch 'github-bot/gh-1606'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1606'
git switch 'github-bot/gh-1606'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1606'
git switch 'main'
git merge --squash 'github-bot/gh-1606'
git switch 'main'
git merge --ff-only 'github-bot/gh-1606'
git switch 'main'
git merge 'github-bot/gh-1606'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.