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

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

📋 Pull Request Information

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

Base: main ← Head: fix/anim-index-hardening


📝 Commits (1)

  • 84a383e anim_index: fix RBF0 string/rig bounds, scan_rpf limit checks, and atomic --rigs/output publishing

📊 Changes

2 files changed (+163 additions, -20 deletions)

View changed files

📝 tests/test_anim_index.py (+81 -0)
📝 tools/anim_index.py (+82 -20)

📄 Description

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.

🔄 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/1460 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/anim-index-hardening` --- ### 📝 Commits (1) - [`84a383e`](https://github.com/ubiquitarianism/leonida/commit/84a383eedd842af14ee70eee7fe30c2894536316) anim_index: fix RBF0 string/rig bounds, scan_rpf limit checks, and atomic --rigs/output publishing ### 📊 Changes **2 files changed** (+163 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_anim_index.py` (+81 -0) 📝 `tools/anim_index.py` (+82 -20) </details> ### 📄 Description 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. --- <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#1491
No description provided.