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

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

📋 Pull Request Information

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

Base: main ← Head: fix/bvh-rehydrate-input-validation


📝 Commits (1)

  • 2320531 bvh_rehydrate: validate leaf order, box child count, --geom spec, and saturate f32 overflow

📊 Changes

2 files changed (+94 additions, -1 deletions)

View changed files

📝 tests/test_bvh_rehydrate.py (+84 -0)
📝 tools/bvh_rehydrate.py (+10 -1)

📄 Description

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.

🔄 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/1393 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/bvh-rehydrate-input-validation` --- ### 📝 Commits (1) - [`2320531`](https://github.com/ubiquitarianism/leonida/commit/23205312b5cb4ef83e1a93844bc70ce84ce1f680) bvh_rehydrate: validate leaf order, box child count, --geom spec, and saturate f32 overflow ### 📊 Changes **2 files changed** (+94 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_bvh_rehydrate.py` (+84 -0) 📝 `tools/bvh_rehydrate.py` (+10 -1) </details> ### 📄 Description 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**. --- <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#1423
No description provided.