world_grid_atlas: harden geometry, alignment, linear_fit, DDS/MHIU bounds, manifests, and strict JSON (WORLD-GRID-ATLAS-VALIDATION-HARDENING) #1506

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

@⁠IlyassRS3 on GitHub · 2026-11-25 02:35 UTC · original
IlyassRS3:fix/world-grid-atlas-hardening → main · +227 −30 · 2 files · 1 commits · open

Claimed in the coordination issue as: WORLD-GRID-ATLAS-VALIDATION-HARDENING (#14)

What and why

Hardens tools/world_grid_atlas.py against malformed geometry, alignment, regression-fit, DDS, MHIU, manifest, and JSON inputs:

  • geometry(): rejects width <= 0, height <= 0, bool dimensions/values, non-3-tuple or non-finite origin, and negative or non-finite zInflation (previously width=0/-512 passed % tile and triggered ZeroDivisionError/inverted boxes, and negative zInflation produced z_min > z_max).
  • cell_box(): rejects bool / non-int cells (previously 1.5 or True silently returned a box) and non-positive grid dimensions.
  • fill_by_order(): rejects negative/bool n_tiles, duplicate cells in order, out-of-range/bool anchor tile indices, and anchor cells absent from order (raising ValueError instead of KeyError or out-of-range placement keys).
  • align(): rejects ragged score rows and non-finite/bool scores, and verifies backtrack indices are valid (previously NaN/-inf scores left arg[j] == -1, silently returning -1 and indexing order[-1]).
  • linear_fit(): checks len(xs) == len(ys) (previously my = fsum(ys) / len(xs) silently computed wrong means and regression parameters on mismatched inputs), rejects non-finite/bool points, and clamps Pearson r to [-1.0, 1.0].
  • read_image(): checks width > 0, height > 0, and len(data) >= DX10_HEADER before struct.unpack_from(..., 128) so a truncated DDS / DX10 file raises a clean ValueError instead of an unhandled struct.error traceback.
  • split_cells() / tile_step(): reject non-positive rows, columns, w, h, and p with ValueError instead of ZeroDivisionError.
  • water_fit() & run(): skip degenerate zero-span / non-finite / truncated MHIU heightmaps cleanly without divide-by-zero warnings, and run water_fit only on WaterSystemHeightMap itself rather than every grid sharing a dictionary set.
  • load_manifests() & write_json(): validate JSON manifest root/items/textures structure (clean ValueError instead of AttributeError) and pass allow_nan=False to json.dump().

Tested

  • python3 -I tests/test_world_grid_atlas.py: 42/42 (26 stdlib tests run and OK; 16 numpy/PIL tests skipped under -I).
  • python3 tests/test_world_grid_atlas.py: 42/42 OK (all stdlib + numpy/PIL forward tests pass).
  • Mutation check against unpatched main (3ff2a2adc): all 10 new regression tests fail (failures=19, errors=5 plus RuntimeWarning: divide by zero on water_fit).
  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.
  • python3 -I scripts/check_no_game_data.py tools/world_grid_atlas.py tests/test_world_grid_atlas.py: clean.
  • python3 -m compileall -q tools/world_grid_atlas.py tests/test_world_grid_atlas.py: clean.

GPUs tested: n/a (Python atlas/analysis tool only)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — no translator rule changed)
**@⁠IlyassRS3** on GitHub · 2026-11-25 02:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1506) `IlyassRS3:fix/world-grid-atlas-hardening` → `main` · +227 −30 · 2 files · 1 commits · open Claimed in the coordination issue as: WORLD-GRID-ATLAS-VALIDATION-HARDENING (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why Hardens `tools/world_grid_atlas.py` against malformed geometry, alignment, regression-fit, DDS, MHIU, manifest, and JSON inputs: - **`geometry()`**: rejects `width <= 0`, `height <= 0`, `bool` dimensions/values, non-3-tuple or non-finite `origin`, and negative or non-finite `zInflation` (previously `width=0`/`-512` passed `% tile` and triggered `ZeroDivisionError`/inverted boxes, and negative `zInflation` produced `z_min > z_max`). - **`cell_box()`**: rejects `bool` / non-`int` cells (previously `1.5` or `True` silently returned a box) and non-positive grid dimensions. - **`fill_by_order()`**: rejects negative/`bool` `n_tiles`, duplicate cells in `order`, out-of-range/`bool` anchor tile indices, and anchor cells absent from `order` (raising `ValueError` instead of `KeyError` or out-of-range placement keys). - **`align()`**: rejects ragged score rows and non-finite/`bool` scores, and verifies backtrack indices are valid (previously `NaN`/`-inf` scores left `arg[j] == -1`, silently returning `-1` and indexing `order[-1]`). - **`linear_fit()`**: checks `len(xs) == len(ys)` (previously `my = fsum(ys) / len(xs)` silently computed wrong means and regression parameters on mismatched inputs), rejects non-finite/`bool` points, and clamps Pearson `r` to `[-1.0, 1.0]`. - **`read_image()`**: checks `width > 0`, `height > 0`, and `len(data) >= DX10_HEADER` before `struct.unpack_from(..., 128)` so a truncated `DDS ` / `DX10` file raises a clean `ValueError` instead of an unhandled `struct.error` traceback. - **`split_cells()` / `tile_step()`**: reject non-positive `rows`, `columns`, `w`, `h`, and `p` with `ValueError` instead of `ZeroDivisionError`. - **`water_fit()` & `run()`**: skip degenerate zero-span / non-finite / truncated MHIU heightmaps cleanly without divide-by-zero warnings, and run `water_fit` only on `WaterSystemHeightMap` itself rather than every grid sharing a dictionary set. - **`load_manifests()` & `write_json()`**: validate JSON manifest root/items/textures structure (clean `ValueError` instead of `AttributeError`) and pass `allow_nan=False` to `json.dump()`. ### Tested - `python3 -I tests/test_world_grid_atlas.py`: 42/42 (26 stdlib tests run and OK; 16 numpy/PIL tests skipped under `-I`). - `python3 tests/test_world_grid_atlas.py`: 42/42 OK (all stdlib + numpy/PIL forward tests pass). - Mutation check against unpatched `main` (`3ff2a2adc`): all 10 new regression tests fail (`failures=19, errors=5` plus `RuntimeWarning: divide by zero` on `water_fit`). - `python3 -I tests/test_text_write_line_endings.py`: 3/3 OK. - `python3 -I scripts/check_no_game_data.py tools/world_grid_atlas.py tests/test_world_grid_atlas.py`: clean. - `python3 -m compileall -q tools/world_grid_atlas.py tests/test_world_grid_atlas.py`: clean. GPUs tested: n/a (Python atlas/analysis tool only) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — no translator rule changed)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:54:36 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 02:35 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 02:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1506#pullrequestreview-6050927084) · **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.
Author
Owner

@⁠ytsodacan on GitHub · 2026-11-25 03:36 UTC · original · edited 2026-11-25 03:44 UTC

[KEEP]

  • Hardening of tools/world_grid_atlas.py reads sensibly (input validation in geometry, cell_box, fill_by_order, align, linear_fit, read_image, manifests, allow_nan=False) and adds tests in tests/test_world_grid_atlas.py.
  • No CI checks have been reported on fix/world-grid-atlas-hardening, so nothing is verified by CI yet; mergeable state is clean.
  • Scope is broad for one PR (about ten functions, 227 additions). It also changes behavior beyond validation: water_fit now runs only for HEIGHT_GRID instead of any is_height grid, and manifest Offset/Index/Width/Height now go through _whole_number, which could reject inputs that previously loaded. A maintainer should confirm both are intended.
  • Re-triage once checks run green.
**@⁠ytsodacan** on GitHub · 2026-11-25 03:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1506#issuecomment-7152068809) · edited 2026-11-25 03:44 UTC **[KEEP]** - Hardening of `tools/world_grid_atlas.py` reads sensibly (input validation in `geometry`, `cell_box`, `fill_by_order`, `align`, `linear_fit`, `read_image`, manifests, `allow_nan=False`) and adds tests in `tests/test_world_grid_atlas.py`. - No CI checks have been reported on `fix/world-grid-atlas-hardening`, so nothing is verified by CI yet; mergeable state is clean. - Scope is broad for one PR (about ten functions, 227 additions). It also changes behavior beyond validation: `water_fit` now runs only for `HEIGHT_GRID` instead of any `is_height` grid, and manifest `Offset`/`Index`/`Width`/`Height` now go through `_whole_number`, which could reject inputs that previously loaded. A maintainer should confirm both are intended. - Re-triage once checks run green.
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/1506/head:github-bot/gh-1506'
git switch 'github-bot/gh-1506'

Merge

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