psocache_usersig: guard second open/mmap, validate --entry/limit/bounds, and reject empty path (PSOCACHE-USERSIG-GUARDS) #1611

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

@⁠IlyassRS3 on GitHub · 2026-11-25 05:54 UTC · original
IlyassRS3:fix/psocache-usersig-guards → main · +137 −41 · 2 files · 1 commits · open

Item ID: PSOCACHE-USERSIG-GUARDS (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/psocache_usersig.py).

What changed

  • Guard the second open() / mmap.mmap() / decode pass in main() (tools/psocache_usersig.py): previously only psocache_inspect.inspect() was inside try/except, so a cache file disappearing, becoming unreadable, or shrinking between inspect() and the second open crashed with an unhandled traceback instead of returning exit code 2. Also check len(m) < report["size"] in shared helper _load_meta().
  • Check --entry bounds before re-opening or parsing meta_index: out-of-range --entry (negative or >= counts["graphics"]) now exits 2 immediately after inspect() instead of re-opening, mmapping, and parsing every meta chunk record first.
  • Reject empty/whitespace cache CLI arguments upfront with exit 2 usage error and enforce allow_nan=False on --json output.
  • Validate programmatic arguments and buffer bounds (summarise, describe_pso, stage_record_refs):
    • summarise() rejects non-int / bool / < 1 limit (previously limit=-3 returned "sampled": -3 and limit=True silently sampled 1).
    • describe_pso() rejects negative / bool / out-of-bounds index with ValueError instead of negative offset wraparound or raw struct.error.
    • stage_record_refs() rejects bool stage and checks a >= 0 and meta_off + a + p + 4 <= len(m) before unpacking.
  • Synthetic regression tests (tests/test_psocache_usersig.py): 4 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_psocache_usersig.py -v: 12 passed
  • python3 -W error -I tests/test_text_write_line_endings.py: passed
  • python3 -I scripts/check_no_game_data.py tools/psocache_usersig.py tests/test_psocache_usersig.py: clean
  • python3 -m compileall -q tools/psocache_usersig.py tests/test_psocache_usersig.py: clean
  • Mutation test (tests/test_psocache_usersig.py against unpatched main:tools/psocache_usersig.py): 8 failures, 3 errors across the 12 tests (all 4 new tests fail on unpatched main).
**@⁠IlyassRS3** on GitHub · 2026-11-25 05:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1611) `IlyassRS3:fix/psocache-usersig-guards` → `main` · +137 −41 · 2 files · 1 commits · open Item ID: `PSOCACHE-USERSIG-GUARDS` (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/psocache_usersig.py`). ## What changed - **Guard the second `open()` / `mmap.mmap()` / decode pass in `main()` (`tools/psocache_usersig.py`)**: previously only `psocache_inspect.inspect()` was inside `try/except`, so a cache file disappearing, becoming unreadable, or shrinking between `inspect()` and the second open crashed with an unhandled traceback instead of returning exit code `2`. Also check `len(m) < report["size"]` in shared helper `_load_meta()`. - **Check `--entry` bounds before re-opening or parsing `meta_index`**: out-of-range `--entry` (negative or `>= counts["graphics"]`) now exits `2` immediately after `inspect()` instead of re-opening, mmapping, and parsing every meta chunk record first. - **Reject empty/whitespace `cache` CLI arguments upfront** with exit `2` usage error and enforce `allow_nan=False` on `--json` output. - **Validate programmatic arguments and buffer bounds (`summarise`, `describe_pso`, `stage_record_refs`)**: - `summarise()` rejects non-`int` / `bool` / `< 1` `limit` (previously `limit=-3` returned `"sampled": -3` and `limit=True` silently sampled 1). - `describe_pso()` rejects negative / `bool` / out-of-bounds `index` with `ValueError` instead of negative offset wraparound or raw `struct.error`. - `stage_record_refs()` rejects `bool` `stage` and checks `a >= 0` and `meta_off + a + p + 4 <= len(m)` before unpacking. - **Synthetic regression tests (`tests/test_psocache_usersig.py`)**: 4 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_psocache_usersig.py -v`: **12 passed** - `python3 -W error -I tests/test_text_write_line_endings.py`: passed - `python3 -I scripts/check_no_game_data.py tools/psocache_usersig.py tests/test_psocache_usersig.py`: clean - `python3 -m compileall -q tools/psocache_usersig.py tests/test_psocache_usersig.py`: clean - Mutation test (`tests/test_psocache_usersig.py` against unpatched `main:tools/psocache_usersig.py`): **8 failures, 3 errors** across the 12 tests (all 4 new tests fail on unpatched `main`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:57:58 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 05:54 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:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1611#pullrequestreview-6052534716) · **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/1611/head:github-bot/gh-1611'
git switch 'github-bot/gh-1611'

Merge

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