world_atlas_accel: validate inputs, contiguous packed_cells, and native output bounds/finiteness #1689

Merged
IlyassRS3 merged 1 commit from upstream-pr/1689 into main 2026-11-28 23:50:43 +00:00
IlyassRS3 commented 2026-11-25 08:17:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T08:17:19Z.


Item ID: WORLD-ATLAS-ACCEL-BOUNDS-AND-FALLBACK (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156815392)

Summary

  • Upfront input validation (tools/world_atlas_accel.py):
    • Reject non-3D cells, non-finite or bool margin, and invalid order sequences (wrong length, out-of-range/negative indices, or bool entries) by returning None before loading or invoking the native library.
    • Ensure packed_cells is C-contiguous and aligned via np.require(_pack(np, cells)[order], requirements=("C", "A")) before passing its raw pointer to ctypes.
  • Native output bounds & finiteness checks:
    • Before indexing order[row.clear] / order[row.placed], validate that row.clear and row.placed are -1 or in 0 .. len(order)-1, and that row.overlap is finite whenever row.placed >= 0, falling back cleanly (return None) to the Python reference instead of crashing with IndexError or propagating corrupt indices / NaN overlaps.
  • Regression tests (tests/test_world_grid_atlas_native.py):
    • Added tests covering malformed margin/order inputs (verifying _load() is never called) and corrupt native output rows (clear/placed out-of-bounds or < -1, non-finite overlap, and end-to-end match_mask() fallback).

Checklist & Verification

  • AI-assisted: yes
  • Game data included: none (python3 -I scripts/check_no_game_data.py tools/world_atlas_accel.py tests/test_world_grid_atlas_native.py passed)
  • GPUs tested: none (hostless macOS NumPy unit test run; optional Rust native tests skipped cleanly)
  • Tests run:
    • python3 -W error -I tests/test_world_grid_atlas_native.py -v: Ran 9 tests ... OK (skipped=4)
    • Mutation test (FallbackTest against unpatched main tools/world_atlas_accel.py): Ran 5 tests ... FAILED (failures=11, errors=3)
    • python3 -m compileall -q make_game.py tools tests: passed
    • python3 -I tests/test_text_write_line_endings.py: Ran 3 tests ... OK
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5487673544 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1689). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T08:17:19Z. --- Item ID: `WORLD-ATLAS-ACCEL-BOUNDS-AND-FALLBACK` (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156815392) ## Summary - **Upfront input validation (`tools/world_atlas_accel.py`)**: - Reject non-3D `cells`, non-finite or `bool` `margin`, and invalid `order` sequences (wrong length, out-of-range/negative indices, or `bool` entries) by returning `None` before loading or invoking the native library. - Ensure `packed_cells` is C-contiguous and aligned via `np.require(_pack(np, cells)[order], requirements=("C", "A"))` before passing its raw pointer to `ctypes`. - **Native output bounds & finiteness checks**: - Before indexing `order[row.clear]` / `order[row.placed]`, validate that `row.clear` and `row.placed` are `-1` or in `0 .. len(order)-1`, and that `row.overlap` is finite whenever `row.placed >= 0`, falling back cleanly (`return None`) to the Python reference instead of crashing with `IndexError` or propagating corrupt indices / `NaN` overlaps. - **Regression tests (`tests/test_world_grid_atlas_native.py`)**: - Added tests covering malformed `margin`/`order` inputs (verifying `_load()` is never called) and corrupt native output rows (`clear`/`placed` out-of-bounds or `< -1`, non-finite `overlap`, and end-to-end `match_mask()` fallback). ## Checklist & Verification - **AI-assisted**: yes - **Game data included**: none (`python3 -I scripts/check_no_game_data.py tools/world_atlas_accel.py tests/test_world_grid_atlas_native.py` passed) - **GPUs tested**: none (hostless macOS NumPy unit test run; optional Rust native tests skipped cleanly) - **Tests run**: - `python3 -W error -I tests/test_world_grid_atlas_native.py -v`: `Ran 9 tests ... OK (skipped=4)` - Mutation test (`FallbackTest` against unpatched `main` `tools/world_atlas_accel.py`): `Ran 5 tests ... FAILED (failures=11, errors=3)` - `python3 -m compileall -q make_game.py tools tests`: passed - `python3 -I tests/test_text_write_line_endings.py`: `Ran 3 tests ... OK`
copilot-pull-request-reviewer[bot] commented 2026-11-25 08:17:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T08:17:33Z.

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:6054004673 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1689#pullrequestreview-6054004673). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T08:17:33Z. **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.
zmasi commented 2026-11-28 11:25:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T11:25:08Z.


#1689 | head f5ef8d0dfa (merged cleanly with main 4a54aedcb) | python tests/test_world_grid_atlas_native.py | red on main: FAILED (failures=11, errors=3, skipped=4) (_load invoked on NaN/inf/bool margins and malformed order, and out-of-bounds clear/placed indices or non-finite overlap values accepted without falling back) | green on PR+main: 9 tests OK (skipped=4) | Windows 11, Python 3.12, NumPy 2.5.1 | AI-assisted: yes

Audited cells.ndim == 3, margin finiteness/non-bool, order length/index/non-bool bounds, np.require(..., requirements=("C", "A")) contiguous aligned cell staging, and post-call row.clear / row.placed / row.overlap bounds & finiteness checks in tools/world_atlas_accel.py. Also verified isolated python -I tests/test_world_grid_atlas_native.py (9 skipped cleanly without NumPy), tests/test_ci_registration.py (18 OK), tests/test_text_write_line_endings.py (3 OK), and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238537988 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1689#issuecomment-7238537988). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T11:25:08Z. --- #1689 | head f5ef8d0dfabd7c411f9237ae3f8d31b56fee92b7 (merged cleanly with main 4a54aedcb) | `python tests/test_world_grid_atlas_native.py` | red on main: `FAILED (failures=11, errors=3, skipped=4)` (`_load` invoked on `NaN`/`inf`/`bool` margins and malformed `order`, and out-of-bounds `clear`/`placed` indices or non-finite `overlap` values accepted without falling back) | green on PR+main: `9 tests OK (skipped=4)` | Windows 11, Python 3.12, NumPy 2.5.1 | AI-assisted: yes Audited `cells.ndim == 3`, `margin` finiteness/non-`bool`, `order` length/index/non-`bool` bounds, `np.require(..., requirements=("C", "A"))` contiguous aligned cell staging, and post-call `row.clear` / `row.placed` / `row.overlap` bounds & finiteness checks in `tools/world_atlas_accel.py`. Also verified isolated `python -I tests/test_world_grid_atlas_native.py` (`9 skipped` cleanly without NumPy), `tests/test_ci_registration.py` (`18 OK`), `tests/test_text_write_line_endings.py` (`3 OK`), and `scripts/check_no_game_data.py`.
TheGeogeo commented 2026-11-28 23:38:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T23:38:30Z.


Tested f5ef8d0df merged (no commit) with main aa918e5d9: Python 3.12.4, Windows 11 10.0.26300, CPU only. check_no_game_data.py is clean.

  • Green: tests/test_world_grid_atlas_native.py, 9 tests pass. 4 are skipped, as on main.
  • Red: with tools/world_atlas_accel.py back to main, 11 failures and 3 errors (must not load).

No blocker from my side.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247566267 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1689#issuecomment-7247566267). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-28T23:38:30Z. --- Tested `f5ef8d0df` merged (no commit) with `main` `aa918e5d9`: Python 3.12.4, Windows 11 10.0.26300, CPU only. `check_no_game_data.py` is clean. - Green: `tests/test_world_grid_atlas_native.py`, 9 tests pass. 4 are skipped, as on `main`. - Red: with `tools/world_atlas_accel.py` back to `main`, 11 failures and 3 errors (`must not load`). No blocker from my side. AI-assisted (Claude Code).
MoonEyes commented 2026-11-28 23:50:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T23:50:46Z.


Merged after TheGeogeo's red/green check (check) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto main 3dee9a5c2 without conflict, and its test file(s) (tests/test_world_grid_atlas_native.py) pass there. Earlier today the same tests failed on main without the PR (red/green) and a bundle with other open PRs showed no new failures. check_no_game_data.py is clean. Windows 11, Python 3.14; no GPU needed for these tests.

AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247701572 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1689#issuecomment-7247701572). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T23:50:46Z. --- Merged after **TheGeogeo**'s red/green check ([check](https://github.com/ProjectLeonida/mandy/pull/1689#issuecomment-7247566267)) (Windows, Python tests, no GPU needed) and a local re-check here. Merged after local re-verification: this PR merged onto `main` 3dee9a5c2 without conflict, and its test file(s) (`tests/test_world_grid_atlas_native.py`) pass there. Earlier today the same tests failed on `main` without the PR (red/green) and a bundle with other open PRs showed no new failures. `check_no_game_data.py` is clean. Windows 11, Python 3.14; no GPU needed for these tests. _AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes._
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!1689
No description provided.