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

Merged
IlyassRS3 merged 1 commit from upstream-pr/1460 into main 2026-11-28 10:16:42 +00:00
IlyassRS3 commented 2026-11-25 00:40:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T00:40:31Z.


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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5482862593 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1460). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T00:40:31Z. --- 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.
copilot-pull-request-reviewer[bot] commented 2026-11-25 00:40:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T00:40:46Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6049765326 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1460#pullrequestreview-6049765326). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T00:40:46Z. **Review:** COMMENTED --- 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.
MoonEyes commented 2026-11-28 10:16:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:16:37Z.


Red/green: the PR's tests fail on main 4938673 and pass on head 84a383eedd (Linux, Python 3.13.18).
Targeted batch of 11 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237790079 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1460#issuecomment-7237790079). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:16:37Z. --- Red/green: the PR's tests fail on main 4938673 and pass on head 84a383eedd84 (Linux, Python 3.13.18). Targeted batch of 11 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1460
No description provided.