bvh_rehydrate: validate leaf order, box child count, --geom spec, and saturate f32 overflow (BVH-REHYDRATE-INPUT-VALIDATION) #1393

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

@⁠IlyassRS3 on GitHub · 2026-11-24 23:13 UTC · original
IlyassRS3:fix/bvh-rehydrate-input-validation → main · +94 −1 · 2 files · 1 commits · open

Item ID: BVH-REHYDRATE-INPUT-VALIDATION

Summary

Fixes four malformed-input / overflow crashes in tools/bvh_rehydrate.py (whose CLI contract is exit status 0 on success and 2 on input errors):

  • Leaf vertex-order validation (write_leaves): rejects invalid low-nibble (a, b) pairs where a == 3, b == 3, or a == b (all 10 non-permutations of {0, 1, 2}) with ValueError instead of crashing with uncaught IndexError on SLOT_OF_ORDER[which] or TypeError when unpacking None slots.
  • Box child-count validation (write_box_groups): rejects box nodes declaring kids > 4 with ValueError instead of unpacking extra child words and failing later inside struct.pack_into.
  • IEEE-754 float32 overflow saturation (f32): catches OverflowError and returns math.copysign(math.inf, x) (matching float_to_half and GPU float32 arithmetic) so large scales in LeafFrame.apply or transforms in Geometry.vertex do not terminate main() with an uncaught OverflowError, while parse_transform continues rejecting non-finite transform entries with ValueError.
  • --geom validation (main): rejects malformed --geom values with extra commas (VB,IB,extra) or an empty vertex-buffer path (,IB) with ValueError (exit 2) instead of silently ignoring trailing fields.

Tests & Verification

  • AI-assisted: yes
  • Host / hardware: macOS (Apple M5, arm64)
  • python3 -m compileall -q make_game.py tools tests — OK
  • python3 -I scripts/check_no_game_data.py tools/bvh_rehydrate.py tests/test_bvh_rehydrate.py — OK
  • python3 -I tests/test_bvh_rehydrate.py -v — 22/22 OK
  • python3 -I tests/test_bvh_rehydrate_stage_cleanup.py -v — 1/1 OK
  • python3 -I tests/test_bvh_packing_check.py — 31/31 OK
  • python3 -I tests/test_bvh_geometry_check.py — 7/7 OK
  • python3 -I tests/test_bvh_slot_check.py — 9/9 OK
  • python3 -I tests/test_bvh_match.py — 42/42 OK
  • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
  • Mutation proof (running tests/test_bvh_rehydrate.py against unpatched upstream/main): 2 failures, 14 errors.
**@⁠IlyassRS3** on GitHub · 2026-11-24 23:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1393) `IlyassRS3:fix/bvh-rehydrate-input-validation` → `main` · +94 −1 · 2 files · 1 commits · open Item ID: `BVH-REHYDRATE-INPUT-VALIDATION` ## Summary Fixes four malformed-input / overflow crashes in `tools/bvh_rehydrate.py` (whose CLI contract is exit status 0 on success and 2 on input errors): - **Leaf vertex-order validation (`write_leaves`)**: rejects invalid low-nibble `(a, b)` pairs where `a == 3`, `b == 3`, or `a == b` (all 10 non-permutations of `{0, 1, 2}`) with `ValueError` instead of crashing with uncaught `IndexError` on `SLOT_OF_ORDER[which]` or `TypeError` when unpacking `None` slots. - **Box child-count validation (`write_box_groups`)**: rejects box nodes declaring `kids > 4` with `ValueError` instead of unpacking extra child words and failing later inside `struct.pack_into`. - **IEEE-754 float32 overflow saturation (`f32`)**: catches `OverflowError` and returns `math.copysign(math.inf, x)` (matching `float_to_half` and GPU float32 arithmetic) so large scales in `LeafFrame.apply` or transforms in `Geometry.vertex` do not terminate `main()` with an uncaught `OverflowError`, while `parse_transform` continues rejecting non-finite transform entries with `ValueError`. - **`--geom` validation (`main`)**: rejects malformed `--geom` values with extra commas (`VB,IB,extra`) or an empty vertex-buffer path (`,IB`) with `ValueError` (exit 2) instead of silently ignoring trailing fields. ## Tests & Verification - **AI-assisted**: yes - **Host / hardware**: macOS (Apple M5, arm64) - `python3 -m compileall -q make_game.py tools tests` — OK - `python3 -I scripts/check_no_game_data.py tools/bvh_rehydrate.py tests/test_bvh_rehydrate.py` — OK - `python3 -I tests/test_bvh_rehydrate.py -v` — 22/22 OK - `python3 -I tests/test_bvh_rehydrate_stage_cleanup.py -v` — 1/1 OK - `python3 -I tests/test_bvh_packing_check.py` — 31/31 OK - `python3 -I tests/test_bvh_geometry_check.py` — 7/7 OK - `python3 -I tests/test_bvh_slot_check.py` — 9/9 OK - `python3 -I tests/test_bvh_match.py` — 42/42 OK - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK - **Mutation proof** (running `tests/test_bvh_rehydrate.py` against unpatched `upstream/main`): **2 failures, 14 errors**.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:49:49 +00:00
Author
Owner

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

Merge

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