OLD-5600: meshlet_page: reject 0-meshlet groups so the page walk terminates; fix u16 running sums and non-finite positions #28

Manually merged
github merged 2 commits from gh-pr/28/head into gh-pr/28/base 2026-11-26 08:41:29 +00:00
Owner

@⁠ItsMrDubey on GitHub · 2026-11-24 02:01 UTC · original
ItsMrDubey:meshlet-zero-group → main · +163 −22 · 2 files · 2 commits · merged 2026-11-24 02:26 UTC

Claimed in the coordination issue as: OLD-5600 (#14)

What and why

Fixes old #5600: a meshlet group whose header says 0 meshlets (0x80000000, 0, 0) passed parse_group and ended 12 bytes in. When the next byte was non-zero, parse_page rounded the position back down to the same 16-byte boundary and re-parsed the same header forever. parse_group now rejects a 0-meshlet group (has no meshlets), so is_mesh_page is false for such a page, and a mid-page one becomes a normal error or a non-mesh data stop.

This carries old PR branch old-pr/10066 by ShotTechOp, cherry-picked onto main with authorship kept. Nothing on main had touched these files since that branch was cut. I checked each of its three fixes against main, and each new test fails there:

  • u16 running-sum wraparound: parse_group only compares the low 16 bits of the running sums, but a group can hold up to 2048 meshlets (more than 65536 refs). group_triangles, cone_agreement, centre_agreement and centre_distance used the wrapped bases from w1 and read the wrong refs. They now add up the bases themselves.
  • non-finite positions: with NaN or inf positions, round(nan) and round(inf) raised inside centre_agreement. NaN also slipped through min()/max(), and a cone normal sum that overflowed counted as a cone. Non-finite axes, radii and lengths are now skipped, and centre_distance returns None.
  • 0-meshlet groups: see above.

My follow-up commit adds a parse_page termination test. It covers a page that starts with an empty group and a page where an empty group comes after a valid one. The test runs the walk in a daemon thread with a 10 s join, so if the bug comes back the test fails instead of hanging the suite.

Tested

Windows 11, Python 3.11.9, no GPU needed.

  • Reproduced on origin/main with a hand-built page (0x80000000,0,0,1 + 12 zero bytes) in a subprocess with a 5 s timeout: HANG (timed out after 5s). On this branch: PageError('page starts with neither a vertex block nor a meshlet group').
  • python -I tests/test_meshlet_page.py: main's tool with the new tests gives FAILED (failures=5, errors=3), with the termination test failing via its guard. This branch gives Ran 71 tests ... OK.
  • Other tests that import the module, all OK: test_analyze_4240_full.py (16), test_draw_ownership.py (11), test_missing_input_exit_codes.py (2), test_tool_stdout_encoding.py, test_vertex_types.py (45, 1 skipped), test_vertex_types_wide_group.py (1).
  • python -I scripts/check_no_game_data.py tools/meshlet_page.py tests/test_meshlet_page.py: clean.

AI-assisted: yes

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • n/a: no translator rule
**@⁠ItsMrDubey** on GitHub · 2026-11-24 02:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/28) `ItsMrDubey:meshlet-zero-group` → `main` · +163 −22 · 2 files · 2 commits · merged 2026-11-24 02:26 UTC Claimed in the coordination issue as: OLD-5600 (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Fixes old #5600: a meshlet group whose header says 0 meshlets (`0x80000000, 0, 0`) passed `parse_group` and ended 12 bytes in. When the next byte was non-zero, `parse_page` rounded the position back down to the same 16-byte boundary and re-parsed the same header forever. `parse_group` now rejects a 0-meshlet group (`has no meshlets`), so `is_mesh_page` is false for such a page, and a mid-page one becomes a normal error or a `non-mesh data` stop. This carries old PR branch `old-pr/10066` by ShotTechOp, cherry-picked onto main with authorship kept. Nothing on main had touched these files since that branch was cut. I checked each of its three fixes against main, and each new test fails there: - **u16 running-sum wraparound:** `parse_group` only compares the low 16 bits of the running sums, but a group can hold up to 2048 meshlets (more than 65536 refs). `group_triangles`, `cone_agreement`, `centre_agreement` and `centre_distance` used the wrapped bases from w1 and read the wrong refs. They now add up the bases themselves. - **non-finite positions:** with NaN or inf positions, `round(nan)` and `round(inf)` raised inside `centre_agreement`. NaN also slipped through `min()`/`max()`, and a cone normal sum that overflowed counted as a cone. Non-finite axes, radii and lengths are now skipped, and `centre_distance` returns None. - **0-meshlet groups:** see above. My follow-up commit adds a `parse_page` termination test. It covers a page that starts with an empty group and a page where an empty group comes after a valid one. The test runs the walk in a daemon thread with a 10 s join, so if the bug comes back the test fails instead of hanging the suite. ### Tested Windows 11, Python 3.11.9, no GPU needed. - Reproduced on origin/main with a hand-built page (`0x80000000,0,0,1` + 12 zero bytes) in a subprocess with a 5 s timeout: `HANG (timed out after 5s)`. On this branch: `PageError('page starts with neither a vertex block nor a meshlet group')`. - `python -I tests/test_meshlet_page.py`: main's tool with the new tests gives `FAILED (failures=5, errors=3)`, with the termination test failing via its guard. This branch gives `Ran 71 tests ... OK`. - Other tests that import the module, all OK: `test_analyze_4240_full.py` (16), `test_draw_ownership.py` (11), `test_missing_input_exit_codes.py` (2), `test_tool_stdout_encoding.py`, `test_vertex_types.py` (45, 1 skipped), `test_vertex_types_wide_group.py` (1). - `python -I scripts/check_no_game_data.py tools/meshlet_page.py tests/test_meshlet_page.py`: clean. AI-assisted: yes ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] n/a: no translator rule
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:41:27 +00:00
github manually merged commit eef19da441 into gh-pr/28/base 2026-11-26 08:41:29 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.