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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1523
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/psin-psch-hardening


📝 Commits (1)

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

📊 Changes

2 files changed (+201 additions, -19 deletions)

View changed files

📝 tests/test_psin_psch.py (+131 -0)
📝 tools/psin_psch.py (+70 -19)

📄 Description

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

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

🔄 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/1523 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/psin-psch-hardening` --- ### 📝 Commits (1) - [`64b23f4`](https://github.com/ubiquitarianism/leonida/commit/64b23f4f17cabfa308a8121749dcc8315562f845) psin_psch: fix PMAP exact_end, schema descriptor checks, head handling, and carve-dir/atomic JSON I/O (PSIN-PSCH-VALIDATION-AND-IO-HARDENING) ### 📊 Changes **2 files changed** (+201 additions, -19 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_psin_psch.py` (+131 -0) 📝 `tools/psin_psch.py` (+70 -19) </details> ### 📄 Description ## 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://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151838167) - 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 --- <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#1551
No description provided.