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

Merged
leonida/mandy
quietfold merged 1 commit from fix/anim-index-hardening into main 2026-11-28 10:16:42 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 00:40:31 +00:00

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.
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] reviewed 2026-11-25 00:40:46 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
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

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)

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 description provided.