[PR #1689] world_atlas_accel: validate inputs, contiguous packed_cells, and native output bounds/finiteness #1703

Open
opened 2026-11-26 20:22:09 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1689
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/world-atlas-accel-bounds-and-fallback


📝 Commits (1)

  • f5ef8d0 world_atlas_accel: validate inputs, contiguous packed_cells, and native output bounds/finiteness

📊 Changes

2 files changed (+71 additions, -5 deletions)

View changed files

📝 tests/test_world_grid_atlas_native.py (+53 -0)
📝 tools/world_atlas_accel.py (+18 -5)

📄 Description

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

🔄 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/1689 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/world-atlas-accel-bounds-and-fallback` --- ### 📝 Commits (1) - [`f5ef8d0`](https://github.com/ubiquitarianism/leonida/commit/f5ef8d0dfabd7c411f9237ae3f8d31b56fee92b7) world_atlas_accel: validate inputs, contiguous packed_cells, and native output bounds/finiteness ### 📊 Changes **2 files changed** (+71 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_world_grid_atlas_native.py` (+53 -0) 📝 `tools/world_atlas_accel.py` (+18 -5) </details> ### 📄 Description 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` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#1703
No description provided.