gamedata_maps: support UTF-8 BOM index.json, validate row fields, and write JSON atomically (GAMEDATA-MAPS-INDEX-AND-ATOMIC-IO) #1526

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

@⁠IlyassRS3 on GitHub · 2026-11-25 03:26 UTC · original
IlyassRS3:fix/gamedata-maps-hardening → main · +126 −18 · 2 files · 1 commits · open

Summary

Hardens carve index loading, payload parsing, and JSON report writing in tools/gamedata_maps.py:

  • UTF-8 BOM & row validation (_read_index_rows, _read_row, _row_nonneg_int, read_payloads): opens index.json with encoding="utf-8-sig", validates that off is a non-negative non-bool integer (preserving the existing row N needs an 'off' diagnostic when missing), validates head (string or None) and size/stored (non-negative non-bool int or None), and stops continuation joins on empty missing chunks.
  • Slice-based PAMH row copy (parse_pamh): checks [offset + start, offset + start + count) against half once per non-empty row and copies max/min slices directly.
  • Atomic JSON report writing (_write_json, main): stages --json output via a sibling temp file with newline="\n", trailing LF, allow_nan=False, file_mode.published_mode, and replace_retry.replace, preserving pre-existing files on error.

Coordination

  • Claimed in the coordination issue as: GAMEDATA-MAPS-INDEX-AND-ATOMIC-IO (#14)
  • Depends on: none

Testing

  • python3 -I tests/test_gamedata_maps.py -v — 28/28 OK (including 3 new regression tests)
  • python3 -I tests/test_gamedata_maps_bad_index.py -v — 8/8 OK
  • python3 -I tests/test_missing_input_exit_codes.py — 2/2 OK
  • python3 -I tests/test_psin_psch.py — 4/4 OK
  • python3 -I tests/test_text_write_line_endings.py — 3/3 OK
  • python3 -I scripts/check_no_game_data.py tools/gamedata_maps.py tests/test_gamedata_maps.py — clean
  • python3 -m compileall -q tools/gamedata_maps.py tests/test_gamedata_maps.py — clean
  • Mutation check against unpatched main:tools/gamedata_maps.py: 3/3 new tests fail (FAILED (failures=5, errors=2)).

Checklist

  • AI-assisted: yes
  • GPUs tested: none required (pure standard-library CPU heightmap/CLI tests, zero game files)
  • No game data, keys, or online services included
**@⁠IlyassRS3** on GitHub · 2026-11-25 03:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1526) `IlyassRS3:fix/gamedata-maps-hardening` → `main` · +126 −18 · 2 files · 1 commits · open ## Summary Hardens carve index loading, payload parsing, and JSON report writing in `tools/gamedata_maps.py`: - **UTF-8 BOM & row validation** (`_read_index_rows`, `_read_row`, `_row_nonneg_int`, `read_payloads`): opens `index.json` with `encoding="utf-8-sig"`, validates that `off` is a non-negative non-`bool` integer (preserving the existing `row N needs an 'off'` diagnostic when missing), validates `head` (string or `None`) and `size`/`stored` (non-negative non-`bool` int or `None`), and stops continuation joins on empty missing chunks. - **Slice-based PAMH row copy** (`parse_pamh`): checks `[offset + start, offset + start + count)` against `half` once per non-empty row and copies max/min slices directly. - **Atomic JSON report writing** (`_write_json`, `main`): stages `--json` output via a sibling temp file with `newline="\n"`, trailing LF, `allow_nan=False`, `file_mode.published_mode`, and `replace_retry.replace`, preserving pre-existing files on error. ## Coordination - Claimed in the coordination issue as: `GAMEDATA-MAPS-INDEX-AND-ATOMIC-IO` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) - Depends on: none ## Testing - `python3 -I tests/test_gamedata_maps.py -v` — 28/28 OK (including 3 new regression tests) - `python3 -I tests/test_gamedata_maps_bad_index.py -v` — 8/8 OK - `python3 -I tests/test_missing_input_exit_codes.py` — 2/2 OK - `python3 -I tests/test_psin_psch.py` — 4/4 OK - `python3 -I tests/test_text_write_line_endings.py` — 3/3 OK - `python3 -I scripts/check_no_game_data.py tools/gamedata_maps.py tests/test_gamedata_maps.py` — clean - `python3 -m compileall -q tools/gamedata_maps.py tests/test_gamedata_maps.py` — clean - Mutation check against unpatched `main:tools/gamedata_maps.py`: 3/3 new tests fail (`FAILED (failures=5, errors=2)`). ## Checklist - AI-assisted: yes - GPUs tested: none required (pure standard-library CPU heightmap/CLI tests, zero game files) - No game data, keys, or online services included
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:23 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 03:26 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 03:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1526#pullrequestreview-6051414703) · **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:34 UTC · original · edited 2026-11-25 03:45 UTC

[KEEP]

  • Looks correct and well scoped to tools/gamedata_maps.py and tests/test_gamedata_maps.py: utf-8-sig index loading, _row_nonneg_int validation of off/stored/size (rejecting bools and negatives), head type check, and an atomic _write_json (temp file + replace_retry.replace, allow_nan=False) with tests for each.
  • CI is still pending (no-game-data, change-scope); the PR is mergeable. Hold for green before merging.
  • The parse_pamh change to slice copies rather than per-cell loops is a behavior-preserving rewrite bundled into a "validation/IO" PR; the bounds check is equivalent, but it is an unrelated optimisation that a reviewer should confirm.
  • Likely a MERGE once CI passes.
**@⁠ytsodacan** on GitHub · 2026-11-25 03:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1526#issuecomment-7152037572) · edited 2026-11-25 03:45 UTC **[KEEP]** - Looks correct and well scoped to `tools/gamedata_maps.py` and `tests/test_gamedata_maps.py`: `utf-8-sig` index loading, `_row_nonneg_int` validation of `off`/`stored`/`size` (rejecting bools and negatives), `head` type check, and an atomic `_write_json` (temp file + `replace_retry.replace`, `allow_nan=False`) with tests for each. - CI is still pending (`no-game-data`, `change-scope`); the PR is mergeable. Hold for green before merging. - The `parse_pamh` change to slice copies rather than per-cell loops is a behavior-preserving rewrite bundled into a "validation/IO" PR; the bounds check is equivalent, but it is an unrelated optimisation that a reviewer should confirm. - Likely a MERGE once CI passes.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 07:45 UTC · original

Independent verification (native Windows, Python 3.11.9): diff vs merge-base reviewed; utf-8-sig index.json, non-neg/non-bool off/head/size/stored validation preserving the row diagnostic, single-bounds parse_pamh slice (indexing equivalence verified), atomic _write_json via NamedTemporaryFile+replace_retry with newline="\n"/allow_nan=False, empty-chunk join guard — all present. Tests reproduce claimed counts exactly: test_gamedata_maps.py 28/28, test_gamedata_maps_bad_index.py 8/8, test_missing_input_exit_codes.py 2/2, test_psin_psch.py 4/4, line-endings 3/3; compileall + check_no_game_data.py clean. AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 07:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1526#issuecomment-7156215179) Independent verification (native Windows, Python 3.11.9): diff vs merge-base reviewed; `utf-8-sig` index.json, non-neg/non-bool `off`/`head`/`size`/`stored` validation preserving the row diagnostic, single-bounds `parse_pamh` slice (indexing equivalence verified), atomic `_write_json` via NamedTemporaryFile+replace_retry with `newline="\n"`/`allow_nan=False`, empty-chunk join guard — all present. Tests reproduce claimed counts exactly: `test_gamedata_maps.py` 28/28, `test_gamedata_maps_bad_index.py` 8/8, `test_missing_input_exit_codes.py` 2/2, `test_psin_psch.py` 4/4, line-endings 3/3; compileall + `check_no_game_data.py` clean. AI-assisted verification.
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/1526/head:github-bot/gh-1526'
git switch 'github-bot/gh-1526'

Merge

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