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

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

@⁠IlyassRS3 on GitHub · 2026-11-25 02:57 UTC · original
IlyassRS3:fix/skinned-glb-hardening → main · +447 −46 · 2 files · 1 commits · open

Claimed in the coordination issue as: SKINNED-GLB-VALIDATION-HARDENING (#14)

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)
**@⁠IlyassRS3** on GitHub · 2026-11-25 02:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1512) `IlyassRS3:fix/skinned-glb-hardening` → `main` · +447 −46 · 2 files · 1 commits · open Claimed in the coordination issue as: SKINNED-GLB-VALIDATION-HARDENING (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:54:56 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 02:57 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 02:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1512#pullrequestreview-6051188768) · **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:34 UTC · original · edited 2026-11-25 03:44 UTC

[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.
**@⁠ytsodacan** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1512#issuecomment-7152035064) · edited 2026-11-25 03:44 UTC **[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.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 07:45 UTC · original

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.

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

Merge

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