skinned_glb: validate GLB chunks, accessor bounds, skeleton cycles, skin streams, and indices (SKINNED-GLB-VALIDATION-HARDENING) #1512

Merged
IlyassRS3 merged 4 commits from upstream-pr/1512 into main 2026-11-29 00:43:51 +00:00
IlyassRS3 commented 2026-11-25 02:57:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T02:57:12Z.


Claimed in the coordination issue as: SKINNED-GLB-VALIDATION-HARDENING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151315288)

What and why

Hardens tools/skinned_glb.py against malformed GLB containers, out-of-bounds accessors, cyclic skeletons, short skin headers, bool-as-int bugs, and invalid glTF primitive indices/attributes:

  1. GLB container validation (read_glb):
    • Validates GLB v2 version, declared container total_length against file size, CHUNK_JSON / CHUNK_BIN chunk types, and JSON/BIN chunk bounds (plus RecursionError on malformed JSON), raising SkinError instead of accepting truncated or non-BIN chunks.
  2. Accessor & bufferView bounds (accessor_bytes):
    • Rejects negative and bool indices, counts, strides, and byte offsets, validates bufferView.byteLength against bin_data, and ensures the accessor span does not extend past its bufferView.
  3. Skeleton hierarchy & matrix guards (_finite_matrix, _bone_name_map, JointSet, PaletteResolver, own_parent_name):
    • _finite_matrix checks isinstance(m, (list, tuple)) and rejects bool elements instead of raising raw TypeError when bind_matrix is None.
    • JointSet.__init__ rejects non-dict bone entries, ignores bool parent values, and rejects self-parenting and multi-bone parent cycles with SkinError instead of producing cyclic glTF node graphs; JointSet.add rejects bool parent.
    • PaletteResolver and own_parent_name guard against non-dict/non-list drawable/skeleton/strings fields and bool parent indices.
  4. Skin stream & weight validation (read_skin_streams, normalise_weights):
    • Rejects short graphics buffers (base + 92 > len(blob)) with SkinError before reading the 23-word section header (previously raised uncaught struct.error on CLI).
    • Rejects negative/bool geometry/model/vertex_buffer indices, bool bone_palette/vertex_count/gfx_off/mesh_blob.sections entries, non-string buffer_files entries, and bool arguments in normalise_weights (and removes a duplicate zeroing line in the NumPy path).
  5. glTF primitive consistency & IBM float32 overflow (build_skinned_glb, _validate_indices):
    • Validates that every copied vertex attribute (NORMAL, TANGENT, TEXCOORD_*, COLOR_0) matches streams["count"], not just POSITION.
    • Validates source index accessors are SCALAR with integer componentType (UNSIGNED_BYTE/UNSIGNED_SHORT/UNSIGNED_INT), positive multiple-of-3 count, and all indices < vertex_count.
    • Catches float32 OverflowError when packing inverseBindMatrices and converts it to SkinError.
  6. CLI upfront directory check (main):
    • Rejects an existing output directory with exit code 2 before building the GLB, and removes the duplicate sys.path.insert.

Tested

  • python3 -I tests/test_skinned_glb.py -v (stdlib path): 38/38 OK (30 existing + 8 new tests in ValidationHardeningTests).
  • python3 tests/test_skinned_glb.py (with NumPy installed): 38/38 OK.
  • Mutation check against unpatched main:tools/skinned_glb.py: all 8 new tests in ValidationHardeningTests fail (FAILED (failures=17, errors=4)).
  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.
  • python3 -I scripts/check_no_game_data.py tools/skinned_glb.py tests/test_skinned_glb.py: clean.
  • python3 -m compileall -q tools/skinned_glb.py tests/test_skinned_glb.py: clean.

GPUs tested: n/a (Python tool, synthetic unit tests only, no GPU or game data)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — no translator rule changes)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5484298247 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1512). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T02:57:12Z. --- Claimed in the coordination issue as: SKINNED-GLB-VALIDATION-HARDENING (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151315288) ### What and why Hardens `tools/skinned_glb.py` against malformed GLB containers, out-of-bounds accessors, cyclic skeletons, short skin headers, `bool`-as-`int` bugs, and invalid glTF primitive indices/attributes: 1. **GLB container validation (`read_glb`)**: - Validates GLB v2 version, declared container `total_length` against file size, `CHUNK_JSON` / `CHUNK_BIN` chunk types, and JSON/BIN chunk bounds (plus `RecursionError` on malformed JSON), raising `SkinError` instead of accepting truncated or non-BIN chunks. 2. **Accessor & bufferView bounds (`accessor_bytes`)**: - Rejects negative and `bool` indices, counts, strides, and byte offsets, validates `bufferView.byteLength` against `bin_data`, and ensures the accessor span does not extend past its `bufferView`. 3. **Skeleton hierarchy & matrix guards (`_finite_matrix`, `_bone_name_map`, `JointSet`, `PaletteResolver`, `own_parent_name`)**: - `_finite_matrix` checks `isinstance(m, (list, tuple))` and rejects `bool` elements instead of raising raw `TypeError` when `bind_matrix` is `None`. - `JointSet.__init__` rejects non-dict bone entries, ignores `bool` `parent` values, and rejects self-parenting and multi-bone parent cycles with `SkinError` instead of producing cyclic glTF node graphs; `JointSet.add` rejects `bool` `parent`. - `PaletteResolver` and `own_parent_name` guard against non-dict/non-list `drawable`/`skeleton`/`strings` fields and `bool` parent indices. 4. **Skin stream & weight validation (`read_skin_streams`, `normalise_weights`)**: - Rejects short graphics buffers (`base + 92 > len(blob)`) with `SkinError` before reading the 23-word section header (previously raised uncaught `struct.error` on CLI). - Rejects negative/`bool` `geometry`/`model`/`vertex_buffer` indices, `bool` `bone_palette`/`vertex_count`/`gfx_off`/`mesh_blob.sections` entries, non-string `buffer_files` entries, and `bool` arguments in `normalise_weights` (and removes a duplicate zeroing line in the NumPy path). 5. **glTF primitive consistency & IBM float32 overflow (`build_skinned_glb`, `_validate_indices`)**: - Validates that every copied vertex attribute (`NORMAL`, `TANGENT`, `TEXCOORD_*`, `COLOR_0`) matches `streams["count"]`, not just `POSITION`. - Validates source index accessors are `SCALAR` with integer `componentType` (`UNSIGNED_BYTE`/`UNSIGNED_SHORT`/`UNSIGNED_INT`), positive multiple-of-3 count, and all indices `< vertex_count`. - Catches float32 `OverflowError` when packing `inverseBindMatrices` and converts it to `SkinError`. 6. **CLI upfront directory check (`main`)**: - Rejects an existing output directory with exit code 2 before building the GLB, and removes the duplicate `sys.path.insert`. ### Tested - `python3 -I tests/test_skinned_glb.py -v` (stdlib path): **38/38 OK** (30 existing + 8 new tests in `ValidationHardeningTests`). - `python3 tests/test_skinned_glb.py` (with NumPy installed): **38/38 OK**. - Mutation check against unpatched `main:tools/skinned_glb.py`: all 8 new tests in `ValidationHardeningTests` fail (`FAILED (failures=17, errors=4)`). - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**. - `python3 -I scripts/check_no_game_data.py tools/skinned_glb.py tests/test_skinned_glb.py`: clean. - `python3 -m compileall -q tools/skinned_glb.py tests/test_skinned_glb.py`: clean. GPUs tested: n/a (Python tool, synthetic unit tests only, no GPU or game data) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — no translator rule changes)
copilot-pull-request-reviewer[bot] commented 2026-11-25 02:57:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T02:57:21Z.

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:6051188768 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1512#pullrequestreview-6051188768). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T02:57:21Z. **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:34:06 +00:00 (Migrated from github.com)

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


[KEEP]

  • Scope is clean: only tools/skinned_glb.py and tests/test_skinned_glb.py (+447/-46), mergeable, and no other open or closed PR touches skinned_glb.
  • CI has not finished: change-scope and no-game-data are still pending, so there is no green signal yet.
  • The change bundles several hardening areas (GLB container, accessor bounds, skeleton cycles, skin headers, bool-as-int); a maintainer will want the test run confirmed before merging.
  • Once CI is green this looks mergeable as-is; no changes requested so far.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7152035064 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1512#issuecomment-7152035064). Originally posted by [ytsodacan](https://github.com/ytsodacan) on 2026-11-25T03:34:06Z. --- **[KEEP]** - Scope is clean: only `tools/skinned_glb.py` and `tests/test_skinned_glb.py` (+447/-46), mergeable, and no other open or closed PR touches `skinned_glb`. - CI has not finished: `change-scope` and `no-game-data` are still pending, so there is no green signal yet. - The change bundles several hardening areas (GLB container, accessor bounds, skeleton cycles, skin headers, bool-as-int); a maintainer will want the test run confirmed before merging. - Once CI is green this looks mergeable as-is; no changes requested so far.
whoalin1 commented 2026-11-25 07:45:18 +00:00 (Migrated from github.com)

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


Independent verification (native Windows, Python 3.11.9, NumPy path exercised): diff vs merge-base reviewed; GLB version/length/chunk/bounds validation + RecursionError, accessor bufferView bounds + bool/negative rejection, JointSet parent-cycle detection, skin-stream index/gfx_off/sections/buffer_files validation, normalise_weights bool guards, _validate_indices (SCALAR/int/multiple-of-3/max<vertex_count), IBM OverflowError→SkinError, CLI output-dir check all present. Tests: test_skinned_glb.py 38/38 (matches claim), test_report_paths.py 22 OK, line-endings 3/3, compileall + check_no_game_data.py clean. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156214669 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1512#issuecomment-7156214669). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T07:45:18Z. --- Independent verification (native Windows, Python 3.11.9, NumPy path exercised): diff vs merge-base reviewed; GLB version/length/chunk/bounds validation + RecursionError, accessor bufferView bounds + bool/negative rejection, JointSet parent-cycle detection, skin-stream index/gfx_off/sections/buffer_files validation, `normalise_weights` bool guards, `_validate_indices` (SCALAR/int/multiple-of-3/max<vertex_count), IBM OverflowError→SkinError, CLI output-dir check all present. Tests: `test_skinned_glb.py` 38/38 (matches claim), `test_report_paths.py` 22 OK, line-endings 3/3, compileall + `check_no_game_data.py` clean. AI-assisted verification.
TheGeogeo commented 2026-11-29 00:17:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T00:17:18Z.


Tested 530d8eb4e merged (no commit) with main 829530dbd: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Green: tests/test_skinned_glb.py, 40 tests pass.
  • Red: with tools/skinned_glb.py back to main, 18 failures and 3 errors (SkinError not raised).

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248007669 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1512#issuecomment-7248007669). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T00:17:18Z. --- Tested `530d8eb4e` merged (no commit) with `main` `829530dbd`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - Green: `tests/test_skinned_glb.py`, 40 tests pass. - Red: with `tools/skinned_glb.py` back to `main`, 18 failures and 3 errors (`SkinError not raised`). No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 00:43:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T00:43:54Z.


Merged after TheGeogeo's red/green check (check) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto main 61b28f3b4 without conflict, and its test file(s) (tests/test_bcpack_tool.py, tests/test_skinned_glb.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248312703 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1512#issuecomment-7248312703). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T00:43:54Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/1512#issuecomment-7248007669)) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto `main` 61b28f3b4 without conflict, and its test file(s) (`tests/test_bcpack_tool.py`, `tests/test_skinned_glb.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
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!1512
No description provided.