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

Merged
leonida/mandy
quietfold merged 1 commit from fix/psocache-usersig-guards into main 2026-11-28 10:38:38 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 05:54:42 +00:00

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).
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`).
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 05:54:49 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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.
MoonEyes commented 2026-11-28 10:38:32 +00:00

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.