bvh_geometry_check: catch NaN leaf bounds, infinite-bound override tolerance blow-up, invalid --geom, and strict JSON (BVH-GEOMETRY-CHECK-NAN-INF-GEOM) #1429

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

@⁠IlyassRS3 on GitHub · 2026-11-25 00:06 UTC · original
IlyassRS3:fix/bvh-geometry-check-nan-inf-geom → main · +129 −7 · 2 files · 1 commits · open

Item ID: BVH-GEOMETRY-CHECK-NAN-INF-GEOM
AI-assisted: yes

Summary

Fixes four soundness and input-validation bugs in tools/bvh_geometry_check.py:

  1. Non-finite (NaN/±inf) leaf and scene bounds silently passed check_bounds():
    • When a leaf's vertices produced NaN bounds, max([box[a] - b[a], ...]) > OUTSIDE_TOLERANCE * extent evaluated to False, and Python's min(union[a], NaN) / max(union[a + 3], NaN) dropped NaN once another finite leaf populated union — falsely reporting leaves_outside=0, bounds_gap=0.0, consistent=True.
    • check_bounds() now rejects non-finite mapped sceneBounds corners and counts any leaf with non-finite bounds as outside (setting bounds_gap = math.inf, consistent = False).
  2. check_overrides() tolerance blew up to +inf on infinite child bounds:
    • Line 98 checked if math.isfinite(value) without checking math.isfinite(b[comp]). When a child bound was ±inf (e.g. a BOX16 bound overflowing half-float range) and the stored override value was finite, tol became +inf, turning lo - tol <= value <= hi + tol into -inf <= value <= +inf and accepting overrides wildly outside [lo, hi].
    • Added _ulp_tol(value, ref) so each bound comparison (b[comp], lo, hi) applies ULP tolerance only when both operands are finite.
  3. Strict --geom VB[,IB] validation and early --json directory check:
    • Rejects malformed --geom specs (len(parts) > 2 or empty VB path such as --geom vb,ib,extra, --geom ,ib, --geom "") with exit status 2 instead of silently dropping extra tokens or opening "".
    • Rejects --json <existing_dir> before reading/rehydrating.
  4. Strict RFC 8259 --json output (allow_nan=False):
    • Non-finite float fields (such as bounds_gap = inf on inconsistent non-finite inputs) are serialized as JSON null with allow_nan=False rather than emitting non-standard NaN/Infinity tokens.

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/bvh_geometry_check.py tests/test_bvh_geometry_check.py — OK
  • python3 -I tests/test_bvh_geometry_check.py -v — 12/12 OK (5 new regression tests)
  • All 11 tests/test_bvh_*.py suites — 214/214 OK
  • 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_bvh_geometry_check.py against unpatched upstream/main 1154976d4): Ran 12 tests — FAILED (failures=5) — all 5 new regression tests fail without this fix.
**@⁠IlyassRS3** on GitHub · 2026-11-25 00:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1429) `IlyassRS3:fix/bvh-geometry-check-nan-inf-geom` → `main` · +129 −7 · 2 files · 1 commits · open Item ID: `BVH-GEOMETRY-CHECK-NAN-INF-GEOM` AI-assisted: yes ### Summary Fixes four soundness and input-validation bugs in `tools/bvh_geometry_check.py`: 1. **Non-finite (`NaN`/`±inf`) leaf and scene bounds silently passed `check_bounds()`**: - When a leaf's vertices produced `NaN` bounds, `max([box[a] - b[a], ...]) > OUTSIDE_TOLERANCE * extent` evaluated to `False`, and Python's `min(union[a], NaN)` / `max(union[a + 3], NaN)` dropped `NaN` once another finite leaf populated `union` — falsely reporting `leaves_outside=0, bounds_gap=0.0, consistent=True`. - `check_bounds()` now rejects non-finite mapped `sceneBounds` corners and counts any leaf with non-finite bounds as outside (setting `bounds_gap = math.inf`, `consistent = False`). 2. **`check_overrides()` tolerance blew up to `+inf` on infinite child bounds**: - Line 98 checked `if math.isfinite(value)` without checking `math.isfinite(b[comp])`. When a child bound was `±inf` (e.g. a BOX16 bound overflowing half-float range) and the stored override `value` was finite, `tol` became `+inf`, turning `lo - tol <= value <= hi + tol` into `-inf <= value <= +inf` and accepting overrides wildly outside `[lo, hi]`. - Added `_ulp_tol(value, ref)` so each bound comparison (`b[comp]`, `lo`, `hi`) applies ULP tolerance only when both operands are finite. 3. **Strict `--geom VB[,IB]` validation and early `--json` directory check**: - Rejects malformed `--geom` specs (`len(parts) > 2` or empty VB path such as `--geom vb,ib,extra`, `--geom ,ib`, `--geom ""`) with exit status 2 instead of silently dropping extra tokens or opening `""`. - Rejects `--json <existing_dir>` before reading/rehydrating. 4. **Strict RFC 8259 `--json` output (`allow_nan=False`)**: - Non-finite float fields (such as `bounds_gap = inf` on inconsistent non-finite inputs) are serialized as JSON `null` with `allow_nan=False` rather than emitting non-standard `NaN`/`Infinity` tokens. ### 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/bvh_geometry_check.py tests/test_bvh_geometry_check.py` — OK - `python3 -I tests/test_bvh_geometry_check.py -v` — 12/12 OK (5 new regression tests) - All 11 `tests/test_bvh_*.py` suites — 214/214 OK - `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_bvh_geometry_check.py` against unpatched `upstream/main` `1154976d4`): `Ran 12 tests — FAILED (failures=5)` — all 5 new regression tests fail without this fix.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:51:09 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 00:06 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:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1429#pullrequestreview-6049483324) · **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

@⁠GeorgiyDemo on GitHub · 2026-11-25 00:20 UTC · original

Tested e5f742680 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 364ab4eab (Python tool only, no GPU):

  • python3 -I tests/test_bvh_geometry_check.py: 12/12 OK at this head (synthetic BVH inputs, no game data).
  • The same file on main fails 5 of 12: test_nan_leaf_bounds_fails_consistency_even_when_other_leaf_covers_bounds, test_nonfinite_scene_bounds_fails_consistency, test_infinite_child_bound_does_not_bypass_override_range_check, test_invalid_geom_spec_and_json_directory_rejected, test_json_report_strict_rfc8259_with_nonfinite_gap — each of the claimed areas has a failing test on main.
  • Did not run the tool on real BVH dumps, only the synthetic tests.

AI-assisted; synthetic fixtures only, no game data.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 00:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1429#issuecomment-7148416202) Tested `e5f742680` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `364ab4eab` (Python tool only, no GPU): - `python3 -I tests/test_bvh_geometry_check.py`: **12/12 OK** at this head (synthetic BVH inputs, no game data). - The same file on `main` fails **5 of 12**: `test_nan_leaf_bounds_fails_consistency_even_when_other_leaf_covers_bounds`, `test_nonfinite_scene_bounds_fails_consistency`, `test_infinite_child_bound_does_not_bypass_override_range_check`, `test_invalid_geom_spec_and_json_directory_rejected`, `test_json_report_strict_rfc8259_with_nonfinite_gap` — each of the claimed areas has a failing test on `main`. - Did not run the tool on real BVH dumps, only the synthetic tests. AI-assisted; synthetic fixtures only, no game data.
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/1429/head:github-bot/gh-1429'
git switch 'github-bot/gh-1429'

Merge

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