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

Open
opened 2026-11-26 20:21:53 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1606
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/root-sig-contract-console-and-validation


📝 Commits (1)

  • 4cfb7c7 root_sig_contract: reject unpaired ptr64_lo on 1-dword tables and harden console/input validation

📊 Changes

2 files changed (+143 additions, -10 deletions)

View changed files

📝 tests/test_root_sig_contract_edges.py (+111 -0)
📝 tools/root_sig_contract.py (+32 -10)

📄 Description

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).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1606 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/root-sig-contract-console-and-validation` --- ### 📝 Commits (1) - [`4cfb7c7`](https://github.com/ubiquitarianism/leonida/commit/4cfb7c7af73421c1b8ee8d81361d00d65cc93e3d) root_sig_contract: reject unpaired ptr64_lo on 1-dword tables and harden console/input validation ### 📊 Changes **2 files changed** (+143 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_root_sig_contract_edges.py` (+111 -0) 📝 `tools/root_sig_contract.py` (+32 -10) </details> ### 📄 Description 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`). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1621
No description provided.