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

Open
opened 2026-11-26 20:21:20 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1433
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/glb-skinning-bbox-validation-atomic


📝 Commits (1)

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

📊 Changes

2 files changed (+125 additions, -11 deletions)

View changed files

📝 tests/test_glb_skinning.py (+69 -0)
📝 tools/glb_skinning.py (+56 -11)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1433 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/glb-skinning-bbox-validation-atomic` --- ### 📝 Commits (1) - [`0b736f9`](https://github.com/ubiquitarianism/leonida/commit/0b736f998608110f47c369a0af48840b6ed0b437) glb_skinning: fix partial-axis NaN bbox, leading-zero sets, zero-count offset, normalized IBM, and atomic JSON write (GLB-SKINNING-BBOX-VALIDATION-ATOMIC) ### 📊 Changes **2 files changed** (+125 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_glb_skinning.py` (+69 -0) 📝 `tools/glb_skinning.py` (+56 -11) </details> ### 📄 Description 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`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1463
No description provided.