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

Merged
IlyassRS3 merged 1 commit from upstream-pr/1433 into main 2026-11-28 10:13:34 +00:00
IlyassRS3 commented 2026-11-25 00:09:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T00:09:48Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5482557412 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1433). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T00:09:48Z. --- 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`.
copilot-pull-request-reviewer[bot] commented 2026-11-25 00:09:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T00:09:56Z.

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:6049512956 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1433#pullrequestreview-6049512956). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T00:09:56Z. **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.
MoonEyes commented 2026-11-28 10:13:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:13:27Z.


Red/green: the PR's tests fail on main 4938673 and pass on head 0b736f9986 (Linux, Python 3.13.18).
Targeted batch of 11 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237754977 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1433#issuecomment-7237754977). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:13:27Z. --- Red/green: the PR's tests fail on main 4938673 and pass on head 0b736f998608 (Linux, Python 3.13.18). Targeted batch of 11 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
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!1433
No description provided.