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

Merged
IlyassRS3 merged 1 commit from upstream-pr/1393 into main 2026-11-28 20:14:39 +00:00
IlyassRS3 commented 2026-11-24 23:13:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-24T23:13:54Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5481925812 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1393). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-24T23:13:54Z. --- 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**.
copilot-pull-request-reviewer[bot] commented 2026-11-24 23:14:05 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T23:14:05Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6048908156 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1393#pullrequestreview-6048908156). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-24T23:14:05Z. **Review:** COMMENTED --- 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 20:14:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T20:14:37Z.


Red/green: On main test_bvh_rehydrate.py has 2 failures and 14 errors (leaf order, --geom spec and f32 overflow not validated), and with the PR all 22 tests pass on Windows 11 at OreoFR's (RTX 4070).
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245141461 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1393#issuecomment-7245141461). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T20:14:37Z. --- Red/green: On main test_bvh_rehydrate.py has 2 failures and 14 errors (leaf order, --geom spec and f32 overflow not validated), and with the PR all 22 tests pass on Windows 11 at OreoFR's (RTX 4070). Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.
OreoFR commented 2026-11-28 21:49:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:49:44Z.


Verified by OreoFR

  • Base: main 3408969a7 + PR head 23205312b
  • Test: python -I tests/test_bvh_rehydrate.py
  • Red on main: 2 FAIL + 14 ERROR (IndexError on leaf order, TypeError --geom, OverflowError f32): the missing validations themselves
  • Green with the PR: 22 OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246303424 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1393#issuecomment-7246303424). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:49:44Z. --- **Verified by OreoFR** - Base: main `3408969a7` + PR head `23205312b` - Test: `python -I tests/test_bvh_rehydrate.py` - Red on main: 2 FAIL + 14 ERROR (IndexError on leaf order, TypeError --geom, OverflowError f32): the missing validations themselves - Green with the PR: 22 OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1393
No description provided.