[PR #888] OLD-7883: audit_shader4_regs: harden stage map loading, bound PSV0 reads, and write JSON atomically #926

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/888
Author: @narekshaghoyandev
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: ubiq-audit-shader4-regs-psv0-stagemap-and-atomic-json


📝 Commits (1)

  • 6c6d66f audit_shader4_regs: harden stage map loading, bound PSV0 reads, and write JSON atomically

📊 Changes

2 files changed (+118 additions, -9 deletions)

View changed files

📝 scripts/audit_shader4_regs.py (+48 -9)
📝 tests/test_audit_shader4_regs.py (+70 -0)

📄 Description

Reopening my original upstream PR #7883 (previously verified on Windows 11 by @TieruYT; zero overlap with #713 --limit), cleanly rebased onto main:

  1. Stage map loading (load_stage_map): Reads index.json with utf-8-sig, guards malformed list entries and non-string/unhashable stage values, and catches RecursionError.
  2. PSV0 bounds checks (read_psv0): Rejects truncated DXBC PSV0 chunks (off + 8 + plen > len(d)) and inner records whose declared rsize exceeds chunk payload bytes (4 + rsize > len(p)).
  3. Atomic JSON output & report path guard (write_json, main): Passes a.json_out directly to protect_input, and publishes --json atomically via tempfile.mkstemp + file_mode.published_mode + replace_retry.replace with allow_nan=False and read-only-safe temp cleanup.

Verification

  • python3 -I tests/test_audit_shader4_regs.py -v: 23/23 pass (all 3 new tests fail/error against main).
  • python3 -I scripts/check_no_game_data.py scripts/audit_shader4_regs.py tests/test_audit_shader4_regs.py: clean.
  • python3 -m compileall -q scripts/audit_shader4_regs.py tests/test_audit_shader4_regs.py: clean.

Claimed in the coordination issue as: OLD-7883 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135201067)
AI-assisted: yes (Gemini)


🔄 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/888 **Author:** [@narekshaghoyandev](https://github.com/narekshaghoyandev) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `ubiq-audit-shader4-regs-psv0-stagemap-and-atomic-json` --- ### 📝 Commits (1) - [`6c6d66f`](https://github.com/ubiquitarianism/leonida/commit/6c6d66fbb8b3b93740f3f7a9a9caca652cadb4db) audit_shader4_regs: harden stage map loading, bound PSV0 reads, and write JSON atomically ### 📊 Changes **2 files changed** (+118 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `scripts/audit_shader4_regs.py` (+48 -9) 📝 `tests/test_audit_shader4_regs.py` (+70 -0) </details> ### 📄 Description Reopening my original upstream PR #7883 (previously verified on Windows 11 by `@TieruYT`; zero overlap with #713 `--limit`), cleanly rebased onto `main`: 1. **Stage map loading (`load_stage_map`)**: Reads `index.json` with `utf-8-sig`, guards malformed list entries and non-string/unhashable `stage` values, and catches `RecursionError`. 2. **PSV0 bounds checks (`read_psv0`)**: Rejects truncated DXBC `PSV0` chunks (`off + 8 + plen > len(d)`) and inner records whose declared `rsize` exceeds chunk payload bytes (`4 + rsize > len(p)`). 3. **Atomic JSON output & report path guard (`write_json`, `main`)**: Passes `a.json_out` directly to `protect_input`, and publishes `--json` atomically via `tempfile.mkstemp` + `file_mode.published_mode` + `replace_retry.replace` with `allow_nan=False` and read-only-safe temp cleanup. ### Verification - `python3 -I tests/test_audit_shader4_regs.py -v`: 23/23 pass (all 3 new tests fail/error against `main`). - `python3 -I scripts/check_no_game_data.py scripts/audit_shader4_regs.py tests/test_audit_shader4_regs.py`: clean. - `python3 -m compileall -q scripts/audit_shader4_regs.py tests/test_audit_shader4_regs.py`: clean. Claimed in the coordination issue as: OLD-7883 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135201067) AI-assisted: yes (Gemini) --- <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#926
No description provided.