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

Open
github-bot wants to merge 1 commit from github-bot/gh-1574 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 04:49 UTC · original
IlyassRS3:fix/rbf0-encode-fail-closed-validation → main · +136 −28 · 2 files · 1 commits · open

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)).
**@⁠IlyassRS3** on GitHub · 2026-11-25 04:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1574) `IlyassRS3:fix/rbf0-encode-fail-closed-validation` → `main` · +136 −28 · 2 files · 1 commits · open 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)`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:56:58 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 04:49 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 04:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1574#pullrequestreview-6052014427) · **reviewed** 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1574/head:github-bot/gh-1574'
git switch 'github-bot/gh-1574'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1574'
git switch 'github-bot/gh-1574'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1574'
git switch 'github-bot/gh-1574'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1574'
git switch 'main'
git merge --squash 'github-bot/gh-1574'
git switch 'main'
git merge --ff-only 'github-bot/gh-1574'
git switch 'main'
git merge 'github-bot/gh-1574'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.