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

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

@⁠IlyassRS3 on GitHub · 2026-11-25 03:19 UTC · original
IlyassRS3:fix/ped-catalogues-hardening → main · +310 −18 · 2 files · 1 commits · open

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 (#14)
  • 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
**@⁠IlyassRS3** on GitHub · 2026-11-25 03:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1522) `IlyassRS3:fix/ped-catalogues-hardening` → `main` · +310 −18 · 2 files · 1 commits · open ## 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://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) - 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:14 +00:00
Author
Owner

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

  • 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.
**@⁠ytsodacan** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1522#issuecomment-7152034238) · edited 2026-11-25 03:45 UTC **[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.
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; 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.

**@⁠whoalin1** on GitHub · 2026-11-25 07:53 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1522#issuecomment-7156365036) 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.
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/1522/head:github-bot/gh-1522'
git switch 'github-bot/gh-1522'

Merge

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