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

Closed
opened 2026-11-26 20:16:44 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/28
Author: @ItsMrDubey
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/24/2026
Merged by: @ubiquitarianism

Base: main ← Head: meshlet-zero-group


📝 Commits (2)

  • 77caf52 meshlet_page: fix u16 running-sum wraparound, non-finite crashes, and 0-meshlet groups
  • eef19da meshlet_page: page walk over a 0-meshlet group terminates, guarded by a regression test

📊 Changes

2 files changed (+163 additions, -22 deletions)

View changed files

📝 tests/test_meshlet_page.py (+116 -0)
📝 tools/meshlet_page.py (+47 -22)

📄 Description

Claimed in the coordination issue as: OLD-5600 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7119646964)

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

🔄 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/28 **Author:** [@ItsMrDubey](https://github.com/ItsMrDubey) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/24/2026 **Merged by:** [@ubiquitarianism](https://github.com/ubiquitarianism) **Base:** `main` ← **Head:** `meshlet-zero-group` --- ### 📝 Commits (2) - [`77caf52`](https://github.com/ubiquitarianism/leonida/commit/77caf525a0461d49191c8b7fc5271a6ddf903361) meshlet_page: fix u16 running-sum wraparound, non-finite crashes, and 0-meshlet groups - [`eef19da`](https://github.com/ubiquitarianism/leonida/commit/eef19da4416cc1ac5273f31c8f65f4464fb2728e) meshlet_page: page walk over a 0-meshlet group terminates, guarded by a regression test ### 📊 Changes **2 files changed** (+163 additions, -22 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_meshlet_page.py` (+116 -0) 📝 `tools/meshlet_page.py` (+47 -22) </details> ### 📄 Description Claimed in the coordination issue as: OLD-5600 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7119646964) ### 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:16:44 +01:00
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#80
No description provided.