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

Merged
leonida/mandy
quietfold merged 1 commit from fix/rbf0-encode-fail-closed-validation into main 2026-11-28 10:53:08 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 04:49:17 +00:00

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)).
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] reviewed 2026-11-25 04:49:33 +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:53:04 +00:00

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)

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