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

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

@⁠narekshaghoyandev on GitHub · 2026-11-24 14:57 UTC · original
narekshaghoyandev:ubiq-audit-shader4-regs-psv0-stagemap-and-atomic-json → main · +118 −9 · 2 files · 1 commits · open

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 (#14)
AI-assisted: yes (Gemini)

**@⁠narekshaghoyandev** on GitHub · 2026-11-24 14:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/888) `narekshaghoyandev:ubiq-audit-shader4-regs-psv0-stagemap-and-atomic-json` → `main` · +118 −9 · 2 files · 1 commits · open 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://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) AI-assisted: yes (Gemini)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:26:27 +00:00
Author
Owner

@⁠KernelSmoker on GitHub · 2026-11-24 15:04 UTC · original · approved these changes

Reviewed the exact submitted head 6c6d66fbb8b3b93740f3f7a9a9caca652cadb4db. The stage-map loader now tolerates malformed entries, BOM-prefixed JSON and recursion errors; PSV0 chunk and record lengths are bounded before slicing/unpacking; report-path collision checks protect inputs; and report publication is atomic with permission preservation and cleanup. Validation on Bazzite/Linux: python3 -I tests/test_audit_shader4_regs.py -v (20/20 passed), python3 -I -m py_compile scripts/audit_shader4_regs.py tests/test_audit_shader4_regs.py, and git diff --check all passed. Synthetic inputs only; no game data or GPU used.

**@⁠KernelSmoker** on GitHub · 2026-11-24 15:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/888#pullrequestreview-6041747358) · **approved these changes** Reviewed the exact submitted head `6c6d66fbb8b3b93740f3f7a9a9caca652cadb4db`. The stage-map loader now tolerates malformed entries, BOM-prefixed JSON and recursion errors; PSV0 chunk and record lengths are bounded before slicing/unpacking; report-path collision checks protect inputs; and report publication is atomic with permission preservation and cleanup. Validation on Bazzite/Linux: `python3 -I tests/test_audit_shader4_regs.py -v` (20/20 passed), `python3 -I -m py_compile scripts/audit_shader4_regs.py tests/test_audit_shader4_regs.py`, and `git diff --check` all passed. Synthetic inputs only; no game data or GPU used.
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/888/head:github-bot/gh-888'
git switch 'github-bot/gh-888'

Merge

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