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

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

📋 Pull Request Information

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

Base: main ← Head: fix/rbf0-encode-fail-closed-validation


📝 Commits (1)

  • e8baf7f rbf0_encode: fail closed on malformed descriptors/nodes/lengths/float overflow and harden CLI

📊 Changes

2 files changed (+136 additions, -28 deletions)

View changed files

📝 tests/test_rbf0_encode.py (+78 -0)
📝 tools/rbf0_encode.py (+58 -28)

📄 Description

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)).

🔄 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/1574 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rbf0-encode-fail-closed-validation` --- ### 📝 Commits (1) - [`e8baf7f`](https://github.com/ubiquitarianism/leonida/commit/e8baf7f7cfc54436ed34e0c4a1bf396690bd8d13) rbf0_encode: fail closed on malformed descriptors/nodes/lengths/float overflow and harden CLI ### 📊 Changes **2 files changed** (+136 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_rbf0_encode.py` (+78 -0) 📝 `tools/rbf0_encode.py` (+58 -28) </details> ### 📄 Description 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)`). --- <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#1594
No description provided.