ped_catalogues: fix filter/BOM/traversal/depth-cap bugs and atomic JSON I/O (PED-CATALOGUES-VALIDATION-AND-IO-HARDENING) #1522

Merged
IlyassRS3 merged 1 commit from upstream-pr/1522 into main 2026-11-28 14:44:48 +00:00
IlyassRS3 commented 2026-11-25 03:19:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T03:19:24Z.


Summary

Fixes several correctness bugs and hardens file/CLI I/O in tools/ped_catalogues.py:

  • Keep name filtering active on empty --names-file / blank --name (_cmd_resolve): passing a comment-only/blank --names-file or blank --name previously passed drawable_names=None to resolve_preset_bindings, disabling filtering and emitting every binding instead of 0 matches.
  • UTF-8 BOM & decode safety (_cmd_resolve, iter_catalogues_in_dir): opens --names-file and carved index.json with encoding="utf-8-sig" (so a leading UTF-8 BOM does not corrupt the first hashed drawable name or break index.json parsing) and catches UnicodeDecodeError cleanly.
  • Path traversal guard in carved index.json (iter_catalogues_in_dir): verifies both primary and continuation row paths stay inside the carved folder via _is_under_dir.
  • Off-by-one MAX_PARENT_DEPTH warning & max_depth validation (parse_catalogue_blocks, resolve_ancestor_tags, resolve_effective_tags, resolve_preset_bindings): checks whether parent.parent_id is non-zero before emitting the depth-cap warning so clean exact-depth chains do not warn falsely, and rejects negative or bool max_depth.
  • Scanner bounds & inspect --max-inflate (iter_catalogues_in_file, iter_catalogues_in_dir, iter_catalogues_in_rpf, _cmd_inspect): validates integer bounds on start, limit, and max_inflate (rejecting non-positive or bool values), adds --max-inflate to inspect, enforces the file-size cap before reading, and reports zlib inflate/cap failures explicitly.
  • Atomic JSON reports & CLI write-error handling (_write_json, _cmd_census, _cmd_inspect, _cmd_resolve): stages JSON output via sibling temp file with newline="\n", allow_nan=False, file_mode.published_mode, and replace_retry.replace, and catches write (OSError, ValueError) with exit code 2 instead of an uncaught traceback.

Coordination

Testing

  • python3 -I tests/test_ped_catalogues.py -v — 16/16 OK (including 6 new regression tests in PedCataloguesHardeningTests)
  • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
  • python3 -I scripts/check_no_game_data.py tools/ped_catalogues.py tests/test_ped_catalogues.py — clean
  • python3 -m compileall -q tools/ped_catalogues.py tests/test_ped_catalogues.py — clean
  • Mutation check against unpatched main:tools/ped_catalogues.py: 6/6 tests in PedCataloguesHardeningTests fail (FAILED (failures=12)).

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
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5484510804 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1522). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T03:19:24Z. --- ## Summary Fixes several correctness bugs and hardens file/CLI I/O in `tools/ped_catalogues.py`: - **Keep name filtering active on empty `--names-file` / blank `--name`** (`_cmd_resolve`): passing a comment-only/blank `--names-file` or blank `--name` previously passed `drawable_names=None` to `resolve_preset_bindings`, disabling filtering and emitting every binding instead of 0 matches. - **UTF-8 BOM & decode safety** (`_cmd_resolve`, `iter_catalogues_in_dir`): opens `--names-file` and carved `index.json` with `encoding="utf-8-sig"` (so a leading UTF-8 BOM does not corrupt the first hashed drawable name or break `index.json` parsing) and catches `UnicodeDecodeError` cleanly. - **Path traversal guard in carved `index.json`** (`iter_catalogues_in_dir`): verifies both primary and continuation row paths stay inside the carved folder via `_is_under_dir`. - **Off-by-one `MAX_PARENT_DEPTH` warning & `max_depth` validation** (`parse_catalogue_blocks`, `resolve_ancestor_tags`, `resolve_effective_tags`, `resolve_preset_bindings`): checks whether `parent.parent_id` is non-zero before emitting the depth-cap warning so clean exact-depth chains do not warn falsely, and rejects negative or `bool` `max_depth`. - **Scanner bounds & `inspect --max-inflate`** (`iter_catalogues_in_file`, `iter_catalogues_in_dir`, `iter_catalogues_in_rpf`, `_cmd_inspect`): validates integer bounds on `start`, `limit`, and `max_inflate` (rejecting non-positive or `bool` values), adds `--max-inflate` to `inspect`, enforces the file-size cap before reading, and reports zlib inflate/cap failures explicitly. - **Atomic JSON reports & CLI write-error handling** (`_write_json`, `_cmd_census`, `_cmd_inspect`, `_cmd_resolve`): stages JSON output via sibling temp file with `newline="\n"`, `allow_nan=False`, `file_mode.published_mode`, and `replace_retry.replace`, and catches write `(OSError, ValueError)` with exit code 2 instead of an uncaught traceback. ## Coordination - Claimed in the coordination issue as: `PED-CATALOGUES-VALIDATION-AND-IO-HARDENING` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151759976) - Depends on: none ## Testing - `python3 -I tests/test_ped_catalogues.py -v` — 16/16 OK (including 6 new regression tests in `PedCataloguesHardeningTests`) - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK - `python3 -I scripts/check_no_game_data.py tools/ped_catalogues.py tests/test_ped_catalogues.py` — clean - `python3 -m compileall -q tools/ped_catalogues.py tests/test_ped_catalogues.py` — clean - Mutation check against unpatched `main:tools/ped_catalogues.py`: 6/6 tests in `PedCataloguesHardeningTests` fail (`FAILED (failures=12)`). ## 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
copilot-pull-request-reviewer[bot] commented 2026-11-25 03:19:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T03:19:36Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051360705 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1522#pullrequestreview-6051360705). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T03:19:36Z. **Review:** COMMENTED --- 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.
ytsodacan commented 2026-11-25 03:34:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ytsodacan on 2026-11-25T03:34:03Z.


[KEEP]

  • Touches only tools/ped_catalogues.py and tests/test_ped_catalogues.py (about 500 diff lines) and bundles several unrelated fixes: filter, BOM, traversal, depth cap and atomic JSON I/O.
  • no-game-data and change-scope checks were still pending when triaged, so there is no green CI signal yet. Merge once they pass.
  • No conflicts reported and no duplicate or overlapping open PR found.
  • A maintainer pass over the traversal and depth-cap behaviour changes is advisable given the size.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152034238 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1522#issuecomment-7152034238). Originally posted by [ytsodacan](https://github.com/ytsodacan) on 2026-11-25T03:34:03Z. --- **[KEEP]** - Touches only `tools/ped_catalogues.py` and `tests/test_ped_catalogues.py` (about 500 diff lines) and bundles several unrelated fixes: filter, BOM, traversal, depth cap and atomic JSON I/O. - `no-game-data` and `change-scope` checks were still pending when triaged, so there is no green CI signal yet. Merge once they pass. - No conflicts reported and no duplicate or overlapping open PR found. - A maintainer pass over the traversal and depth-cap behaviour changes is advisable given the size.
whoalin1 commented 2026-11-25 07:53:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T07:53:21Z.


Independent verification (native Windows, Python 3.11.9 — stdlib-only, representative): diff vs merge-base reviewed; empty names-file filter stays active, utf-8-sig, _is_under_dir traversal guard, depth-cap warning fix, --max-inflate, atomic _write_json all present; tests 16/16+3/3+2/2, mutation reproduces FAILED(12). compileall + check_no_game_data clean. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156365036 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1522#issuecomment-7156365036). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T07:53:21Z. --- Independent verification (native Windows, Python 3.11.9 — stdlib-only, representative): diff vs merge-base reviewed; empty names-file filter stays active, utf-8-sig, _is_under_dir traversal guard, depth-cap warning fix, --max-inflate, atomic _write_json all present; tests 16/16+3/3+2/2, mutation reproduces FAILED(12). compileall + check_no_game_data clean. AI-assisted verification.
MoonEyes commented 2026-11-28 14:44:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T14:44:42Z.


Red/green: pytest tests/test_ped_catalogues.py fails on main (12 failed, 10 passed, 1 subtests passed) and passes on head 8ab99b80f9 merged with main (16 passed, 10 subtests passed).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7240898670 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1522#issuecomment-7240898670). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:44:42Z. --- Red/green: `pytest tests/test_ped_catalogues.py` fails on main (12 failed, 10 passed, 1 subtests passed) and passes on head 8ab99b80f913 merged with main (16 passed, 10 subtests passed). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1522
No description provided.