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

Open
github-bot wants to merge 1 commit from github-bot/gh-1689 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 08:17 UTC · original
IlyassRS3:fix/world-atlas-accel-bounds-and-fallback → main · +71 −5 · 2 files · 1 commits · open

Item ID: WORLD-ATLAS-ACCEL-BOUNDS-AND-FALLBACK (claimed in #1608)

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
**@⁠IlyassRS3** on GitHub · 2026-11-25 08:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1689) `IlyassRS3:fix/world-atlas-accel-bounds-and-fallback` → `main` · +71 −5 · 2 files · 1 commits · open Item ID: `WORLD-ATLAS-ACCEL-BOUNDS-AND-FALLBACK` (claimed in https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ## 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`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:00:54 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 08:17 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 08:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1689#pullrequestreview-6054004673) · **reviewed** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1689/head:github-bot/gh-1689'
git switch 'github-bot/gh-1689'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1689'
git switch 'github-bot/gh-1689'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1689'
git switch 'github-bot/gh-1689'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1689'
git switch 'main'
git merge --squash 'github-bot/gh-1689'
git switch 'main'
git merge --ff-only 'github-bot/gh-1689'
git switch 'main'
git merge 'github-bot/gh-1689'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.