psin_psch: fix PMAP exact_end, schema checks, head handling, and carve-dir/atomic JSON I/O (PSIN-PSCH-VALIDATION-AND-IO-HARDENING) #1523

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

@⁠IlyassRS3 on GitHub · 2026-11-25 03:23 UTC · original
IlyassRS3:fix/psin-psch-hardening → main · +201 −19 · 2 files · 1 commits · open

Summary

Fixes several concrete bugs and hardens validation and report I/O in tools/psin_psch.py:

  • PMAP exact_end calculation (decode_pmap): computes the data-area end from max(b["offset"] + b["length"] for b in blocks) instead of row-order blocks[-1], so valid PMAP tables with a trailing empty block or out-of-order final row are no longer falsely rejected.
  • Self-referencing descriptor & duplicate hash detection (check_psch_schema): rejects self-referencing PSCH_TYPE_ARRAY (elem_idx == idx) and PSCH_TYPE_MAP (k_idx == idx / v_idx == idx) descriptors and reports duplicate struct or enum hashes in PSCH instead of silently overwriting earlier entries.
  • Safe head row filtering (_has_psin_head, scan_target): handles None/non-string head fields in carve index.json rows without raising an uncaught AttributeError, and matches uppercase "5053494E" prefixes as well as lowercase.
  • Complete --carve-dir & pre-parse overwrite protection (check_report_path, main): checks .bin payloads inside --carve-dir via gm.check_report_path (not only index.json), and runs the initial check_report_path guard before reading index.json so --json <dir>/index.json still exits 2 even when index.json is corrupt.
  • Atomic JSON report writing (_write_json, main): stages --json output in a sibling temp file with newline="\n", trailing LF, allow_nan=False, file_mode.published_mode, and replace_retry.replace, preserving pre-existing files on failure.

Coordination

  • Claimed in the coordination issue as: PSIN-PSCH-VALIDATION-AND-IO-HARDENING (#14)
  • Depends on: none

Testing

  • python3 -I tests/test_psin_psch.py -v — 9/9 OK (including 5 new regression tests)
  • python3 -I tests/test_missing_input_exit_codes.py — 2/2 OK
  • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
  • python3 -I scripts/check_no_game_data.py tools/psin_psch.py tests/test_psin_psch.py — clean
  • python3 -m compileall -q tools/psin_psch.py tests/test_psin_psch.py — clean
  • Mutation check against unpatched main:tools/psin_psch.py: 5/5 new tests fail (FAILED (failures=3, errors=2)).

Checklist

  • AI-assisted: yes
  • GPUs tested: none required (pure standard-library CPU container/CLI tests, zero game files)
  • No game data, keys, or online services included
**@⁠IlyassRS3** on GitHub · 2026-11-25 03:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1523) `IlyassRS3:fix/psin-psch-hardening` → `main` · +201 −19 · 2 files · 1 commits · open ## Summary Fixes several concrete bugs and hardens validation and report I/O in `tools/psin_psch.py`: - **PMAP `exact_end` calculation** (`decode_pmap`): computes the data-area end from `max(b["offset"] + b["length"] for b in blocks)` instead of row-order `blocks[-1]`, so valid PMAP tables with a trailing empty block or out-of-order final row are no longer falsely rejected. - **Self-referencing descriptor & duplicate hash detection** (`check_psch_schema`): rejects self-referencing `PSCH_TYPE_ARRAY` (`elem_idx == idx`) and `PSCH_TYPE_MAP` (`k_idx == idx` / `v_idx == idx`) descriptors and reports duplicate struct or enum hashes in `PSCH` instead of silently overwriting earlier entries. - **Safe `head` row filtering** (`_has_psin_head`, `scan_target`): handles `None`/non-string `head` fields in carve `index.json` rows without raising an uncaught `AttributeError`, and matches uppercase `"5053494E"` prefixes as well as lowercase. - **Complete `--carve-dir` & pre-parse overwrite protection** (`check_report_path`, `main`): checks `.bin` payloads inside `--carve-dir` via `gm.check_report_path` (not only `index.json`), and runs the initial `check_report_path` guard before reading `index.json` so `--json <dir>/index.json` still exits 2 even when `index.json` is corrupt. - **Atomic JSON report writing** (`_write_json`, `main`): stages `--json` output in a sibling temp file with `newline="\n"`, trailing LF, `allow_nan=False`, `file_mode.published_mode`, and `replace_retry.replace`, preserving pre-existing files on failure. ## Coordination - Claimed in the coordination issue as: `PSIN-PSCH-VALIDATION-AND-IO-HARDENING` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) - Depends on: none ## Testing - `python3 -I tests/test_psin_psch.py -v` — 9/9 OK (including 5 new regression tests) - `python3 -I tests/test_missing_input_exit_codes.py` — 2/2 OK - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK - `python3 -I scripts/check_no_game_data.py tools/psin_psch.py tests/test_psin_psch.py` — clean - `python3 -m compileall -q tools/psin_psch.py tests/test_psin_psch.py` — clean - Mutation check against unpatched `main:tools/psin_psch.py`: 5/5 new tests fail (`FAILED (failures=3, errors=2)`). ## Checklist - AI-assisted: yes - GPUs tested: none required (pure standard-library CPU container/CLI tests, zero game files) - No game data, keys, or online services included
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:16 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 03:23 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 03:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1523#pullrequestreview-6051393929) · **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.
Author
Owner

@⁠ytsodacan on GitHub · 2026-11-25 03:34 UTC · original · edited 2026-11-25 03:45 UTC

[KEEP]

  • Scoped to tools/psin_psch.py and tests/test_psin_psch.py; the PMAP exact_end fix (use max block end instead of the last row), duplicate struct/enum hash checks and atomic JSON writes look reasonable, with new tests for each.
  • Only no-game-data and change-scope checks are reported and both were still pending, so there is no green CI signal yet. Merge once they pass.
  • This is a broad bundle (PMAP, schema checks, head handling, carve-dir guard, atomic I/O) in one PR; splitting would ease review but is not required.
  • No conflicts and no overlapping open PR found (#873, the related earlier change, is already merged).
**@⁠ytsodacan** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1523#issuecomment-7152033873) · edited 2026-11-25 03:45 UTC **[KEEP]** - Scoped to `tools/psin_psch.py` and `tests/test_psin_psch.py`; the PMAP `exact_end` fix (use max block end instead of the last row), duplicate struct/enum hash checks and atomic JSON writes look reasonable, with new tests for each. - Only `no-game-data` and `change-scope` checks are reported and both were still pending, so there is no green CI signal yet. Merge once they pass. - This is a broad bundle (PMAP, schema checks, head handling, carve-dir guard, atomic I/O) in one PR; splitting would ease review but is not required. - No conflicts and no overlapping open PR found (#873, the related earlier change, is already merged).
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 07:53 UTC · original

Independent verification (native Windows, Python 3.11.9 — stdlib-only, representative): diff vs merge-base reviewed; PMAP exact_end via max(block end), duplicate/self-ref schema checks, lowercase head match, check_report_path rows coverage, atomic _write_json all present; tests 9/9+2/2+3/3, mutation reproduces FAILED(3,2). compileall + check_no_game_data clean. AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 07:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1523#issuecomment-7156365508) Independent verification (native Windows, Python 3.11.9 — stdlib-only, representative): diff vs merge-base reviewed; PMAP exact_end via max(block end), duplicate/self-ref schema checks, lowercase head match, check_report_path rows coverage, atomic _write_json all present; tests 9/9+2/2+3/3, mutation reproduces FAILED(3,2). compileall + check_no_game_data clean. AI-assisted verification.
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/1523/head:github-bot/gh-1523'
git switch 'github-bot/gh-1523'

Merge

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