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
leonida/mandy
quietfold merged 1 commit from fix/glb-skinning-bbox-validation-atomic into main 2026-11-28 10:13:34 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 00:09:48 +00:00

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.
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] reviewed 2026-11-25 00:09:56 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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

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)

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 description provided.