glb_skinning: fix partial-axis NaN bbox, leading-zero sets, zero-count offset, normalized IBM, and atomic JSON write (GLB-SKINNING-BBOX-VALIDATION-ATOMIC) #1433

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

@⁠IlyassRS3 on GitHub · 2026-11-25 00:09 UTC · original
IlyassRS3:fix/glb-skinning-bbox-validation-atomic → main · +125 −11 · 2 files · 1 commits · open

Item ID: GLB-SKINNING-BBOX-VALIDATION-ATOMIC
AI-assisted: yes

Summary

Fixes five bugs in tools/glb_skinning.py:

  1. Partial-axis non-finite POSITION crashed write_json(..., allow_nan=False):
    • _bbox() only checked whether any scalar component across all three axes was finite (if not finite:). When one axis had only NaN/±inf values while the other axes were finite, _bbox() returned [inf, ...] / [-inf, ...], causing json.dumps(..., allow_nan=False) in write_json() to raise ValueError.
    • _bbox() now tracks finite values per axis and returns (None, None, non_finite) unless all three axes have finite values.
  2. Leading-zero skinning attribute set indices (JOINTS_00, WEIGHTS_01):
    • ATTRIBUTE_RE matched (\d+), collapsing JOINTS_00 into set 0 (either silently ignored when JOINTS_0 existed, or producing misleading missing-pair errors).
    • ATTRIBUTE_RE now matches canonical 0|[1-9]\d* per glTF 2.0 §3.7.2.1, and leading-zero keys emit an explicit validation error.
  3. count == 0 accessor skipped byteOffset > view_length bounds check:
    • _Reader.read() only checked bufferView bounds inside if count:, accepting out-of-range byteOffset values on zero-count accessors.
  4. Normalized inverseBindMatrices not rejected:
    • _validate_skins() now rejects normalized: true on inverseBindMatrices (consistent with glTF 2.0 §3.6.2.2 and the existing FLOAT weight / joint checks).
  5. Atomic write_json() publishing and early --json directory rejection:
    • write_json() now resolves symlinks, rejects symlink cycles (ELOOP) and existing directories (IsADirectoryError), and stages writes via tempfile.NamedTemporaryFile + file_mode.published_mode + os.replace with cleanup on failure so existing reports are never truncated on write errors. main() rejects --json <dir> before reading the GLB.

Verification (macOS Apple M5, arm64, Python 3.14; no game files)

  • python3 -m compileall -q make_game.py tools tests — OK
  • python3 -I scripts/check_no_game_data.py tools/glb_skinning.py tests/test_glb_skinning.py — OK
  • python3 -I tests/test_glb_skinning.py -v — 32/32 OK (6 new regression tests)
  • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
  • python3 -I tests/test_ci_registration.py — 16/16 OK
  • Mutation proof (running the new tests/test_glb_skinning.py against unpatched upstream/main 1154976d4): Ran 32 tests — FAILED (failures=5) — catches partial-axis [inf, 0.0, 0.0] bbox, leading-zero JOINTS_00, zero-count byteOffset past bufferView, normalized inverseBindMatrices, and non-atomic write_json.
**@⁠IlyassRS3** on GitHub · 2026-11-25 00:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1433) `IlyassRS3:fix/glb-skinning-bbox-validation-atomic` → `main` · +125 −11 · 2 files · 1 commits · open Item ID: `GLB-SKINNING-BBOX-VALIDATION-ATOMIC` AI-assisted: yes ### Summary Fixes five bugs in `tools/glb_skinning.py`: 1. **Partial-axis non-finite `POSITION` crashed `write_json(..., allow_nan=False)`**: - `_bbox()` only checked whether *any* scalar component across all three axes was finite (`if not finite:`). When one axis had only `NaN`/`±inf` values while the other axes were finite, `_bbox()` returned `[inf, ...]` / `[-inf, ...]`, causing `json.dumps(..., allow_nan=False)` in `write_json()` to raise `ValueError`. - `_bbox()` now tracks finite values per axis and returns `(None, None, non_finite)` unless all three axes have finite values. 2. **Leading-zero skinning attribute set indices (`JOINTS_00`, `WEIGHTS_01`)**: - `ATTRIBUTE_RE` matched `(\d+)`, collapsing `JOINTS_00` into set `0` (either silently ignored when `JOINTS_0` existed, or producing misleading missing-pair errors). - `ATTRIBUTE_RE` now matches canonical `0|[1-9]\d*` per glTF 2.0 §3.7.2.1, and leading-zero keys emit an explicit validation error. 3. **`count == 0` accessor skipped `byteOffset > view_length` bounds check**: - `_Reader.read()` only checked `bufferView` bounds inside `if count:`, accepting out-of-range `byteOffset` values on zero-count accessors. 4. **Normalized `inverseBindMatrices` not rejected**: - `_validate_skins()` now rejects `normalized: true` on `inverseBindMatrices` (consistent with glTF 2.0 §3.6.2.2 and the existing `FLOAT` weight / joint checks). 5. **Atomic `write_json()` publishing and early `--json` directory rejection**: - `write_json()` now resolves symlinks, rejects symlink cycles (`ELOOP`) and existing directories (`IsADirectoryError`), and stages writes via `tempfile.NamedTemporaryFile` + `file_mode.published_mode` + `os.replace` with cleanup on failure so existing reports are never truncated on write errors. `main()` rejects `--json <dir>` before reading the GLB. ### Verification (macOS Apple M5, arm64, Python 3.14; no game files) - `python3 -m compileall -q make_game.py tools tests` — OK - `python3 -I scripts/check_no_game_data.py tools/glb_skinning.py tests/test_glb_skinning.py` — OK - `python3 -I tests/test_glb_skinning.py -v` — 32/32 OK (6 new regression tests) - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK - `python3 -I tests/test_ci_registration.py` — 16/16 OK - **Mutation proof** (running the new `tests/test_glb_skinning.py` against unpatched `upstream/main` `1154976d4`): `Ran 32 tests — FAILED (failures=5)` — catches partial-axis `[inf, 0.0, 0.0]` bbox, leading-zero `JOINTS_00`, zero-count `byteOffset` past `bufferView`, normalized `inverseBindMatrices`, and non-atomic `write_json`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:51:20 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 00:09 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 00:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1433#pullrequestreview-6049512956) · **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.
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/1433/head:github-bot/gh-1433'
git switch 'github-bot/gh-1433'

Merge

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