rbf0_encode: fail closed on malformed descriptors/nodes/lengths/float overflow and harden CLI (RBF0-ENCODE-FAIL-CLOSED-VALIDATION) #1574

Merged
IlyassRS3 merged 1 commit from upstream-pr/1574 into main 2026-11-28 10:53:08 +00:00
IlyassRS3 commented 2026-11-25 04:49:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T04:49:17Z.


Item ID: RBF0-ENCODE-FAIL-CLOSED-VALIDATION (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch tools/rbf0_encode.py)

Summary

  • Validate descriptor table entries by declared index: _Writer.__init__ previously assumed descriptors was a list of dicts in positional order and indexed d["index"] directly, crashing with AttributeError/KeyError on malformed edited reports and mis-mapping out-of-order entries. Now malformed descriptors raise EncodeError("descriptor", ...), explicit indices map by index (defaulting to position when omitted), and conflicting duplicate indices are refused.
  • Catch huge-integer float() overflow inside float_bits(): float(10**400) previously raised an uncaught OverflowError before reaching struct.pack(), bypassing EncodeError("value", ...) and aborting write_all().
  • Fail closed on malformed node shapes and boolean recorded lengths:
    • vec3: require float_special (when present) to be a 3-element list (previously non-sequences raised TypeError and 3-char strings like "nan" passed len == 3).
    • string / text: reject bool values for byte_length / length (previously True == 1 and False == 0 slipped past equality checks).
    • element: require attributes and content to be lists of dicts, raising EncodeError("value", ...) instead of TypeError/AttributeError.
  • Harden write_all() and main(): accept UTF-8 BOM reports (utf-8-sig) and catch RecursionError, reject empty/whitespace output directories before os.makedirs(), catch OSError in --check, and don't format boolean refused offsets (True/False) as hex 0x1/0x0.

Testing

  • AI-assisted: yes
  • GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files)
  • python3 -W error -I tests/test_rbf0_encode.py -v: 41/41 passed
  • python3 -W error -I tests/test_text_write_line_endings.py -v: 3/3 passed
  • python3 -I scripts/check_no_game_data.py tools/rbf0_encode.py tests/test_rbf0_encode.py: passed
  • python3 -m compileall -q make_game.py tools tests: passed
  • Mutation check against unpatched main:tools/rbf0_encode.py: all 4 new tests fail (FAILED (failures=2, errors=5)).
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485371990 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1574). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T04:49:17Z. --- Item ID: `RBF0-ENCODE-FAIL-CLOSED-VALIDATION` (new item; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at PR time — confirmed 0 open PRs touch `tools/rbf0_encode.py`) ## Summary - **Validate descriptor table entries by declared `index`**: `_Writer.__init__` previously assumed `descriptors` was a list of dicts in positional order and indexed `d["index"]` directly, crashing with `AttributeError`/`KeyError` on malformed edited reports and mis-mapping out-of-order entries. Now malformed descriptors raise `EncodeError("descriptor", ...)`, explicit indices map by `index` (defaulting to position when omitted), and conflicting duplicate indices are refused. - **Catch huge-integer `float()` overflow inside `float_bits()`**: `float(10**400)` previously raised an uncaught `OverflowError` before reaching `struct.pack()`, bypassing `EncodeError("value", ...)` and aborting `write_all()`. - **Fail closed on malformed node shapes and boolean recorded lengths**: - `vec3`: require `float_special` (when present) to be a 3-element `list` (previously non-sequences raised `TypeError` and 3-char strings like `"nan"` passed `len == 3`). - `string` / `text`: reject `bool` values for `byte_length` / `length` (previously `True == 1` and `False == 0` slipped past equality checks). - `element`: require `attributes` and `content` to be lists of dicts, raising `EncodeError("value", ...)` instead of `TypeError`/`AttributeError`. - **Harden `write_all()` and `main()`**: accept UTF-8 BOM reports (`utf-8-sig`) and catch `RecursionError`, reject empty/whitespace output directories before `os.makedirs()`, catch `OSError` in `--check`, and don't format boolean refused offsets (`True`/`False`) as hex `0x1`/`0x0`. ## Testing - AI-assisted: yes - GPUs tested: none (CPU/Python stdlib tool; no GPU, no game files) - `python3 -W error -I tests/test_rbf0_encode.py -v`: **41/41 passed** - `python3 -W error -I tests/test_text_write_line_endings.py -v`: **3/3 passed** - `python3 -I scripts/check_no_game_data.py tools/rbf0_encode.py tests/test_rbf0_encode.py`: passed - `python3 -m compileall -q make_game.py tools tests`: passed - Mutation check against unpatched `main:tools/rbf0_encode.py`: all 4 new tests fail (`FAILED (failures=2, errors=5)`).
copilot-pull-request-reviewer[bot] commented 2026-11-25 04:49:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T04:49:33Z.

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:6052014427 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1574#pullrequestreview-6052014427). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T04:49:33Z. **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:53:04 +00:00 (Migrated from github.com)

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


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 19 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:7238184405 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1574#issuecomment-7238184405). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:53:04Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 19 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!1574
No description provided.