anim_index: fix RBF0 string/rig bounds, scan_rpf limit checks, and atomic --rigs/output publishing (ANIM-INDEX-HARDENING) #1460

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

@⁠IlyassRS3 on GitHub · 2026-11-25 00:40 UTC · original
IlyassRS3:fix/anim-index-hardening → main · +163 −20 · 2 files · 1 commits · open

Claimed in the coordination issue as: ANIM-INDEX-HARDENING

Summary

Hardens tools/anim_index.py across RBF0 parsing, archive scan API validation, error handling, and atomic output publishing:

  1. Truncated _fd_string rejection: unlike _u16_string(), _fd_string() did not check len(raw) != n, silently accepting truncated prefixes past the end of data.
  2. Scoped parse_rbf0() rig pairing: previously, an orphan source tag with no rig before the next source or next rigset stole the following entry's/rigset's rig via bisect_left(rig_offsets, source_at). Now caps end at min(next_source, next_rigset) and skips sources with rig_at >= end.
  3. Direct-API scan_rpf() validation: limit=0 previously treated if limit: as unbounded and limit < 0 silently scanned 0 bytes; booleans for start/limit were also accepted. Now validates start and limit >= 1 (non-bool int).
  4. Parse --rigs before writing out + atomic staged publishing:
    • Previously, main() wrote a.out before collecting/parsing --rigs, clobbering an existing index output even when --rigs failed with exit code 2 (no RBF0 stream or parse_rbf0 error). --rigs is now collected and parsed first (with OSError/zlib.error caught cleanly).
    • Both write_output() (JSON and CSV) and --rigs now publish atomically via _write_text_atomic() (tempfile.NamedTemporaryFile sibling + file_mode.published_mode + os.replace + chmod(0o600) cleanup), rejecting trailing directory separators and symlink loops (ELOOP).
    • Also catches OSError when listing an unreadable a.source directory during the pre-flight overwrite guard instead of raising an uncaught PermissionError traceback.

Testing

  • AI-assisted: yes
  • Host: macOS Apple M5 (arm64), Python 3.14 (CPU-only, synthetic RPF9/RBF0 fixtures only, no game data)
  • python3 -m compileall -q make_game.py tools tests -> clean
  • python3 -I scripts/check_no_game_data.py tools/anim_index.py tests/test_anim_index.py -> clean
  • python3 -I tests/test_anim_index.py -v -> 53/53 OK (6 new tests)
  • python3 -I tests/test_text_write_line_endings.py -> 3/3 OK
  • python3 -I tests/test_ci_registration.py -> 16/16 OK
  • Mutation proof (running the new tests/test_anim_index.py on unpatched upstream/main b4b7756e8): FAILED (failures=9, errors=1) across all 6 new tests.
**@⁠IlyassRS3** on GitHub · 2026-11-25 00:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1460) `IlyassRS3:fix/anim-index-hardening` → `main` · +163 −20 · 2 files · 1 commits · open Claimed in the coordination issue as: ANIM-INDEX-HARDENING ## Summary Hardens `tools/anim_index.py` across RBF0 parsing, archive scan API validation, error handling, and atomic output publishing: 1. **Truncated `_fd_string` rejection**: unlike `_u16_string()`, `_fd_string()` did not check `len(raw) != n`, silently accepting truncated prefixes past the end of `data`. 2. **Scoped `parse_rbf0()` rig pairing**: previously, an orphan source tag with no rig before the next source or next rigset stole the following entry's/rigset's rig via `bisect_left(rig_offsets, source_at)`. Now caps `end` at `min(next_source, next_rigset)` and skips sources with `rig_at >= end`. 3. **Direct-API `scan_rpf()` validation**: `limit=0` previously treated `if limit:` as unbounded and `limit < 0` silently scanned 0 bytes; booleans for `start`/`limit` were also accepted. Now validates `start` and `limit >= 1` (non-bool `int`). 4. **Parse `--rigs` before writing `out` + atomic staged publishing**: - Previously, `main()` wrote `a.out` before collecting/parsing `--rigs`, clobbering an existing index output even when `--rigs` failed with exit code 2 (`no RBF0 stream` or `parse_rbf0` error). `--rigs` is now collected and parsed first (with `OSError`/`zlib.error` caught cleanly). - Both `write_output()` (JSON and CSV) and `--rigs` now publish atomically via `_write_text_atomic()` (`tempfile.NamedTemporaryFile` sibling + `file_mode.published_mode` + `os.replace` + `chmod(0o600)` cleanup), rejecting trailing directory separators and symlink loops (`ELOOP`). - Also catches `OSError` when listing an unreadable `a.source` directory during the pre-flight overwrite guard instead of raising an uncaught `PermissionError` traceback. ## Testing - **AI-assisted**: yes - **Host**: macOS Apple M5 (`arm64`), Python 3.14 (CPU-only, synthetic RPF9/RBF0 fixtures only, no game data) - `python3 -m compileall -q make_game.py tools tests` -> clean - `python3 -I scripts/check_no_game_data.py tools/anim_index.py tests/test_anim_index.py` -> clean - `python3 -I tests/test_anim_index.py -v` -> **53/53 OK** (6 new tests) - `python3 -I tests/test_text_write_line_endings.py` -> **3/3 OK** - `python3 -I tests/test_ci_registration.py` -> **16/16 OK** - **Mutation proof** (running the new `tests/test_anim_index.py` on unpatched `upstream/main` `b4b7756e8`): `FAILED (failures=9, errors=1)` across all 6 new tests.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:52:10 +00:00
Author
Owner

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

Merge

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