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

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

@⁠IlyassRS3 on GitHub · 2026-11-25 03:14 UTC · original
IlyassRS3:fix/ped-assemble-hardening → main · +969 −103 · 2 files · 1 commits · open

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

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

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

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

Merge

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