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

Open
opened 2026-11-26 20:21:38 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1520
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/ped-assemble-hardening


📝 Commits (1)

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

📊 Changes

2 files changed (+969 additions, -103 deletions)

View changed files

📝 tests/test_ped_assemble.py (+387 -0)
📝 tools/ped_assemble.py (+582 -103)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1520 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/ped-assemble-hardening` --- ### 📝 Commits (1) - [`6366c36`](https://github.com/ubiquitarianism/leonida/commit/6366c36d5d46be94f9b4279786f09a77334c26a2) ped_assemble: harden output guards, atomic JSON reports, and input/skeleton validation (PED-ASSEMBLE-VALIDATION-AND-IO-HARDENING) ### 📊 Changes **2 files changed** (+969 additions, -103 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_ped_assemble.py` (+387 -0) 📝 `tools/ped_assemble.py` (+582 -103) </details> ### 📄 Description ## 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1549
No description provided.