ped_assemble: harden output guards, atomic JSON reports, and input/skeleton validation (PED-ASSEMBLE-VALIDATION-AND-IO-HARDENING) #1520

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

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


Summary

Hardens tools/ped_assemble.py across output overwrite/collision safety, atomic JSON report publishing, binary glTF container bounds, skeleton hierarchy/IBM integrity, tolerance validation, and malformed JSON/manifest error handling:

  • Output overwrite, collision, and directory guards (_check_output_paths): checks -o/--out and --json across assemble, cull-overlap, and inspect-seams against existing directories, each other, direct inputs, and transitively loaded manifest parts / external PNG texture files using report_paths.same_report_path.
  • Atomic JSON reports & strict finite JSON (_write_json_report, build_assembled_glb): stages JSON reports in a sibling temp file with newline="\n", allow_nan=False, file_mode.published_mode, and replace_retry.replace (preserving pre-existing files on error and cleaning up temp files), and enforces allow_nan=False in build_assembled_glb.
  • GLB chunk bounds & triangle index validation (read_glb_parts): rejects total_len < 20, chunk headers whose pos + chunk_len > total_len, unconsumed trailing bytes within total_len, and out-of-range triangle vertex indices.
  • Skeleton hierarchy & float32 validation (_validate_skeleton, _pack_f32_vec, _pack_u16_vec4, build_assembled_glb): rejects self-parent and multi-joint parent cycles, out-of-range or bool parents, unsupported skeleton.coord_space, non-16-float inverse_bind_matrix entries on y-up skeletons, non-finite values, and float32-overflowing attributes/IBMs with PedAssembleError instead of silent corruption or raw OverflowError.
  • CLI & API tolerance validation: validates finite standing_offset, non-negative finite tolerances (--waist-tol, --nipple-tol, --genital-tol, --plane-tol, --vertex-tol, --weld-tol, --tol, --overlap-tol), and normal_cos_min in [-1, 1] in both build_parser() and core API functions.
  • Manifest cycle & malformed input handling (load_parts_from_path, _read_png_spec, _parse_material_dict, _part_from_dict, _skeleton_from_dict, main): detects cyclic JSON manifests, validates base64: payloads and material fields (base_color_factor, alpha_mode, finite factors), validates JSON part/triangle bounds, and catches OSError / glb_writer.GlbError in main() for clean exit-2 ERROR: reporting.

Coordination

Testing

  • python3 -I tests/test_ped_assemble.py -v — 22/22 OK (including 6 new regression tests in ValidationAndIoHardeningTests)
  • python3 -I tests/test_ped_assemble_malformed_glb.py — 8/8 OK
  • python3 -I tests/test_ped_assemble_sparse_glb.py — 7/7 OK
  • python3 -I tests/test_ped_extra_uvs.py — 7/7 OK
  • python3 -I tests/test_ped_glb_material_defaults.py — 6/6 OK
  • python3 -I tests/test_ped_json_textures.py — 4/4 OK
  • python3 -I tests/test_ped_snorm.py — 5/5 OK
  • python3 -I tests/test_json_bom_inputs.py — 10/10 OK
  • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
  • python3 -I scripts/check_no_game_data.py tools/ped_assemble.py tests/test_ped_assemble.py — clean
  • python3 -m compileall -q tools/ped_assemble.py tests/test_ped_assemble.py — clean
  • Mutation check against unpatched main:tools/ped_assemble.py: 6/6 tests in ValidationAndIoHardeningTests fail (FAILED (failures=5, errors=1)).

Checklist

  • AI-assisted: yes
  • GPUs tested: none required (pure standard-library CPU geometry/GLB tests, zero game files)
  • No game data, keys, or online services included
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5484461470 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1520). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T03:14:27Z. --- ## Summary Hardens `tools/ped_assemble.py` across output overwrite/collision safety, atomic JSON report publishing, binary glTF container bounds, skeleton hierarchy/IBM integrity, tolerance validation, and malformed JSON/manifest error handling: - **Output overwrite, collision, and directory guards** (`_check_output_paths`): checks `-o`/`--out` and `--json` across `assemble`, `cull-overlap`, and `inspect-seams` against existing directories, each other, direct inputs, and transitively loaded manifest parts / external PNG texture files using `report_paths.same_report_path`. - **Atomic JSON reports & strict finite JSON** (`_write_json_report`, `build_assembled_glb`): stages JSON reports in a sibling temp file with `newline="\n"`, `allow_nan=False`, `file_mode.published_mode`, and `replace_retry.replace` (preserving pre-existing files on error and cleaning up temp files), and enforces `allow_nan=False` in `build_assembled_glb`. - **GLB chunk bounds & triangle index validation** (`read_glb_parts`): rejects `total_len < 20`, chunk headers whose `pos + chunk_len > total_len`, unconsumed trailing bytes within `total_len`, and out-of-range triangle vertex indices. - **Skeleton hierarchy & float32 validation** (`_validate_skeleton`, `_pack_f32_vec`, `_pack_u16_vec4`, `build_assembled_glb`): rejects self-parent and multi-joint parent cycles, out-of-range or `bool` parents, unsupported `skeleton.coord_space`, non-16-float `inverse_bind_matrix` entries on `y-up` skeletons, non-finite values, and float32-overflowing attributes/IBMs with `PedAssembleError` instead of silent corruption or raw `OverflowError`. - **CLI & API tolerance validation**: validates finite `standing_offset`, non-negative finite tolerances (`--waist-tol`, `--nipple-tol`, `--genital-tol`, `--plane-tol`, `--vertex-tol`, `--weld-tol`, `--tol`, `--overlap-tol`), and `normal_cos_min` in `[-1, 1]` in both `build_parser()` and core API functions. - **Manifest cycle & malformed input handling** (`load_parts_from_path`, `_read_png_spec`, `_parse_material_dict`, `_part_from_dict`, `_skeleton_from_dict`, `main`): detects cyclic JSON manifests, validates `base64:` payloads and material fields (`base_color_factor`, `alpha_mode`, finite factors), validates JSON part/triangle bounds, and catches `OSError` / `glb_writer.GlbError` in `main()` for clean exit-2 `ERROR:` reporting. ## Coordination - Claimed in the coordination issue as: `PED-ASSEMBLE-VALIDATION-AND-IO-HARDENING` (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151612040) - Depends on: none ## Testing - `python3 -I tests/test_ped_assemble.py -v` — 22/22 OK (including 6 new regression tests in `ValidationAndIoHardeningTests`) - `python3 -I tests/test_ped_assemble_malformed_glb.py` — 8/8 OK - `python3 -I tests/test_ped_assemble_sparse_glb.py` — 7/7 OK - `python3 -I tests/test_ped_extra_uvs.py` — 7/7 OK - `python3 -I tests/test_ped_glb_material_defaults.py` — 6/6 OK - `python3 -I tests/test_ped_json_textures.py` — 4/4 OK - `python3 -I tests/test_ped_snorm.py` — 5/5 OK - `python3 -I tests/test_json_bom_inputs.py` — 10/10 OK - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK - `python3 -I scripts/check_no_game_data.py tools/ped_assemble.py tests/test_ped_assemble.py` — clean - `python3 -m compileall -q tools/ped_assemble.py tests/test_ped_assemble.py` — clean - Mutation check against unpatched `main:tools/ped_assemble.py`: 6/6 tests in `ValidationAndIoHardeningTests` fail (`FAILED (failures=5, errors=1)`). ## Checklist - AI-assisted: yes - GPUs tested: none required (pure standard-library CPU geometry/GLB tests, zero game files) - No game data, keys, or online services included
copilot-pull-request-reviewer[bot] commented 2026-11-25 03:14:44 +00:00 (Migrated from github.com)

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

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:6051318825 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1520#pullrequestreview-6051318825). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T03:14:44Z. **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:33:56 +00:00 (Migrated from github.com)

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


[KEEP]

  • Large change (tools/ped_assemble.py +582/-103, tests/test_ped_assemble.py +387) bundling several concerns: output-path guards, atomic JSON reports, GLB bounds, skeleton validation, tolerance validation, and manifest cycle handling. It is hard to review as one unit; splitting could help, though it is claimed as a single item in the coordination issue.
  • Positives: 6 new regression tests, with a mutation check against unpatched main reported in the description; no duplicate/overlapping PR found; no conflicts.
  • CI is pending (change-scope, no-game-data) and no independent tester has reported yet.
  • Needs a careful maintainer review of the new CLI validation and exit-code behavior before merge.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152032405 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1520#issuecomment-7152032405). Originally posted by [ytsodacan](https://github.com/ytsodacan) on 2026-11-25T03:33:56Z. --- **[KEEP]** - Large change (`tools/ped_assemble.py` +582/-103, `tests/test_ped_assemble.py` +387) bundling several concerns: output-path guards, atomic JSON reports, GLB bounds, skeleton validation, tolerance validation, and manifest cycle handling. It is hard to review as one unit; splitting could help, though it is claimed as a single item in the coordination issue. - Positives: 6 new regression tests, with a mutation check against unpatched main reported in the description; no duplicate/overlapping PR found; no conflicts. - CI is pending (`change-scope`, `no-game-data`) and no independent tester has reported yet. - Needs a careful maintainer review of the new CLI validation and exit-code behavior before merge.
whoalin1 commented 2026-11-25 07:53:19 +00:00 (Migrated from github.com)

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


Independent verification (native Windows, Python 3.11.9 — stdlib-only, representative): diff vs merge-base reviewed; output guards, atomic JSON, GLB chunk/skeleton/CLI validation all present; tests 22/22+8/8+7/7+7/7+6/6+4/4+5/5+10/10+3/3 and mutation check reproduces claimed FAILED(5,1). compileall + check_no_game_data clean. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156364493 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1520#issuecomment-7156364493). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T07:53:19Z. --- Independent verification (native Windows, Python 3.11.9 — stdlib-only, representative): diff vs merge-base reviewed; output guards, atomic JSON, GLB chunk/skeleton/CLI validation all present; tests 22/22+8/8+7/7+7/7+6/6+4/4+5/5+10/10+3/3 and mutation check reproduces claimed FAILED(5,1). compileall + check_no_game_data clean. AI-assisted verification.
MoonEyes commented 2026-11-28 14:43:21 +00:00 (Migrated from github.com)

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


Red/green: pytest tests/test_ped_assemble.py fails on main (6 failed, 16 passed, 3 subtests passed) and passes on head 6366c36d5d merged with main (22 passed, 11 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:7240881996 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1520#issuecomment-7240881996). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:43:21Z. --- Red/green: `pytest tests/test_ped_assemble.py` fails on main (6 failed, 16 passed, 3 subtests passed) and passes on head 6366c36d5d46 merged with main (22 passed, 11 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!1520
No description provided.