ped_catalogues: fix filter/BOM/traversal/depth-cap bugs and atomic JSON I/O (PED-CATALOGUES-VALIDATION-AND-IO-HARDENING) #1522
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!1522
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/ped-catalogues-hardening"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Summary
Fixes several correctness bugs and hardens file/CLI I/O in
tools/ped_catalogues.py:--names-file/ blank--name(_cmd_resolve): passing a comment-only/blank--names-fileor blank--namepreviously passeddrawable_names=Nonetoresolve_preset_bindings, disabling filtering and emitting every binding instead of 0 matches._cmd_resolve,iter_catalogues_in_dir): opens--names-fileand carvedindex.jsonwithencoding="utf-8-sig"(so a leading UTF-8 BOM does not corrupt the first hashed drawable name or breakindex.jsonparsing) and catchesUnicodeDecodeErrorcleanly.index.json(iter_catalogues_in_dir): verifies both primary and continuation row paths stay inside the carved folder via_is_under_dir.MAX_PARENT_DEPTHwarning &max_depthvalidation (parse_catalogue_blocks,resolve_ancestor_tags,resolve_effective_tags,resolve_preset_bindings): checks whetherparent.parent_idis non-zero before emitting the depth-cap warning so clean exact-depth chains do not warn falsely, and rejects negative orboolmax_depth.inspect --max-inflate(iter_catalogues_in_file,iter_catalogues_in_dir,iter_catalogues_in_rpf,_cmd_inspect): validates integer bounds onstart,limit, andmax_inflate(rejecting non-positive orboolvalues), adds--max-inflatetoinspect, enforces the file-size cap before reading, and reports zlib inflate/cap failures explicitly._write_json,_cmd_census,_cmd_inspect,_cmd_resolve): stages JSON output via sibling temp file withnewline="\n",allow_nan=False,file_mode.published_mode, andreplace_retry.replace, and catches write(OSError, ValueError)with exit code 2 instead of an uncaught traceback.Coordination
PED-CATALOGUES-VALIDATION-AND-IO-HARDENING(https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151759976)Testing
python3 -I tests/test_ped_catalogues.py -v— 16/16 OK (including 6 new regression tests inPedCataloguesHardeningTests)python3 -I tests/test_text_write_line_endings.py— 3/3 OKpython3 -I scripts/check_no_game_data.py tools/ped_catalogues.py tests/test_ped_catalogues.py— cleanpython3 -m compileall -q tools/ped_catalogues.py tests/test_ped_catalogues.py— cleanmain:tools/ped_catalogues.py: 6/6 tests inPedCataloguesHardeningTestsfail (FAILED (failures=12)).Checklist
[KEEP]
tools/ped_catalogues.pyandtests/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-dataandchange-scopechecks were still pending when triaged, so there is no green CI signal yet. Merge once they pass.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.
Red/green:
pytest tests/test_ped_catalogues.pyfails 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)