restofworld_index: validate scan bounds, fix carve index .bk2/BOM, harden I/O (RESTOFWORLD-INDEX-VALIDATION-AND-IO) #1535

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

@⁠IlyassRS3 on GitHub · 2026-11-25 03:47 UTC · original
IlyassRS3:fix/restofworld-index-hardening → main · +169 −29 · 2 files · 1 commits · open

What changed

  • Python API bound validation (tools/restofworld_index.py:scan_rpf, scan_dir): reject bool, <= 0 limit/max_inflate, and non-integer start with ValueError. Previously scan_rpf(..., limit=0) silently scanned the entire archive, negative limit produced a negative span, and max_inflate <= 0 silently skipped every stream.
  • Bink 2 header window check (tools/restofworld_index.py:scan_rpf): require s + 0x1C <= end before reading header dimensions (matching tools/rpf9_carve.py) and bound the slice passed to classify() by s + blen.
  • Carve index BOM, .bk2 mapping, and summary validation (tools/restofworld_index.py:_carve_index):
    • Open index.json with encoding="utf-8-sig" so UTF-8 BOM-prefixed indexes are not silently ignored.
    • Map type == "bink2" rows to <off>.bk2 (matching rpf9_carve.py) instead of hardcoding .bin.
    • Validate off, stored, span, zero_padding, and unread_bytes are non-negative non-bool integers so malformed summary values fall back cleanly instead of crashing scan_dir().
  • Source/payload overwrite guard and atomic JSON hardening (tools/restofworld_index.py:write_output, main):
    • Use report_paths.same_report_path (with os.path.samestat for hardlinks) so case-folding, NFD, and dangling symlink aliases to the source archive or carved directory payloads/index.json are caught before scanning.
    • Serialize JSON with allow_nan=False and a trailing LF, publish via replace_retry.replace, allow optional argv=None in main(argv=None), and catch ValueError alongside OSError when writing.
  • Tests (tests/test_restofworld_index.py): added 3 synthetic regression tests covering API validation, BOM/.bk2/malformed-summary carve indexes, strict JSON/trailing LF, and dangling-symlink overwrite guards.

Claimed in the coordination issue as:

RESTOFWORLD-INDEX-VALIDATION-AND-IO (#14)

How it was tested

  • python3 -I -W error tests/test_restofworld_index.py: 37/37 passed (0 warnings).
  • python3 -I tests/test_bad_input_errors.py: 11/11 passed.
  • python3 -I tests/test_csv_line_endings.py: 2/2 passed.
  • python3 -I tests/test_limit_window.py: 1/1 passed.
  • python3 -I tests/test_printable_bytes.py: 4/4 passed.
  • python3 -I tests/test_zero_span.py: 3/3 passed.
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • python3 -I scripts/check_no_game_data.py tools/restofworld_index.py tests/test_restofworld_index.py: passed.
  • python3 -m compileall -q tools/restofworld_index.py tests/test_restofworld_index.py: passed.
  • Mutation check against unpatched main:tools/restofworld_index.py: all 3 new tests fail (FAILED (failures=3)), all 34 baseline tests pass.

Metadata

  • AI-assisted: yes
  • GPUs tested: none (CPU-only synthetic archive / directory / CLI unit tests on macOS arm64; no game files used)
**@⁠IlyassRS3** on GitHub · 2026-11-25 03:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1535) `IlyassRS3:fix/restofworld-index-hardening` → `main` · +169 −29 · 2 files · 1 commits · open ## What changed - **Python API bound validation (`tools/restofworld_index.py:scan_rpf`, `scan_dir`)**: reject `bool`, `<= 0` `limit`/`max_inflate`, and non-integer `start` with `ValueError`. Previously `scan_rpf(..., limit=0)` silently scanned the entire archive, negative `limit` produced a negative `span`, and `max_inflate <= 0` silently skipped every stream. - **Bink 2 header window check (`tools/restofworld_index.py:scan_rpf`)**: require `s + 0x1C <= end` before reading header dimensions (matching `tools/rpf9_carve.py`) and bound the slice passed to `classify()` by `s + blen`. - **Carve index BOM, `.bk2` mapping, and summary validation (`tools/restofworld_index.py:_carve_index`)**: - Open `index.json` with `encoding="utf-8-sig"` so UTF-8 BOM-prefixed indexes are not silently ignored. - Map `type == "bink2"` rows to `<off>.bk2` (matching `rpf9_carve.py`) instead of hardcoding `.bin`. - Validate `off`, `stored`, `span`, `zero_padding`, and `unread_bytes` are non-negative non-bool integers so malformed summary values fall back cleanly instead of crashing `scan_dir()`. - **Source/payload overwrite guard and atomic JSON hardening (`tools/restofworld_index.py:write_output`, `main`)**: - Use `report_paths.same_report_path` (with `os.path.samestat` for hardlinks) so case-folding, NFD, and dangling symlink aliases to the source archive or carved directory payloads/`index.json` are caught before scanning. - Serialize JSON with `allow_nan=False` and a trailing LF, publish via `replace_retry.replace`, allow optional `argv=None` in `main(argv=None)`, and catch `ValueError` alongside `OSError` when writing. - **Tests (`tests/test_restofworld_index.py`)**: added 3 synthetic regression tests covering API validation, BOM/`.bk2`/malformed-summary carve indexes, strict JSON/trailing LF, and dangling-symlink overwrite guards. ## Claimed in the coordination issue as: `RESTOFWORLD-INDEX-VALIDATION-AND-IO` (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ## How it was tested - `python3 -I -W error tests/test_restofworld_index.py`: 37/37 passed (0 warnings). - `python3 -I tests/test_bad_input_errors.py`: 11/11 passed. - `python3 -I tests/test_csv_line_endings.py`: 2/2 passed. - `python3 -I tests/test_limit_window.py`: 1/1 passed. - `python3 -I tests/test_printable_bytes.py`: 4/4 passed. - `python3 -I tests/test_zero_span.py`: 3/3 passed. - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. - `python3 -I scripts/check_no_game_data.py tools/restofworld_index.py tests/test_restofworld_index.py`: passed. - `python3 -m compileall -q tools/restofworld_index.py tests/test_restofworld_index.py`: passed. - Mutation check against unpatched `main:tools/restofworld_index.py`: all 3 new tests fail (`FAILED (failures=3)`), all 34 baseline tests pass. ## Metadata - AI-assisted: yes - GPUs tested: none (CPU-only synthetic archive / directory / CLI unit tests on macOS arm64; no game files used)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:55:42 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 03:47 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:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1535#pullrequestreview-6051572954) · **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/1535/head:github-bot/gh-1535'
git switch 'github-bot/gh-1535'

Merge

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