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

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

📋 Pull Request Information

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

Base: main ← Head: fix/gamedata-maps-hardening


📝 Commits (1)

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

📊 Changes

2 files changed (+126 additions, -18 deletions)

View changed files

📝 tests/test_gamedata_maps.py (+57 -0)
📝 tools/gamedata_maps.py (+69 -18)

📄 Description

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

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

🔄 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/1526 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/gamedata-maps-hardening` --- ### 📝 Commits (1) - [`2a384e1`](https://github.com/ubiquitarianism/leonida/commit/2a384e13f76313541478cbc3d1afe57b539b9be3) gamedata_maps: support UTF-8 BOM index.json, validate row fields, and write JSON atomically (GAMEDATA-MAPS-INDEX-AND-ATOMIC-IO) ### 📊 Changes **2 files changed** (+126 additions, -18 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_gamedata_maps.py` (+57 -0) 📝 `tools/gamedata_maps.py` (+69 -18) </details> ### 📄 Description ## 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://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7151890540) - 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 --- <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#1557
No description provided.