[PR #2386] rbf0_encode: write back a short-count element with text or child content (RBF0-ENCODE-SHORT-COUNT-CONTENT) #2386

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/2386
Author: @syfyra
Created: 11/26/2026
Status: 🔄 Open

Base: main ← Head: fix/rbf0-encode-short-count-content


📝 Commits (1)

  • 4f1ca18 rbf0_encode: write back a short-count element with text or child content (RBF0-ENCODE-SHORT-COUNT-CONTENT)

📊 Changes

2 files changed (+23 additions, -1 deletions)

View changed files

📝 tests/test_rbf0_encode.py (+15 -0)
📝 tools/rbf0_encode.py (+8 -1)

📄 Description

Claimed in the coordination issue as: RBF0-ENCODE-SHORT-COUNT-CONTENT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198218440)

What and why

tools/rbf0_encode.py writes an rbf0_tree.py document back to bytes and fails closed. docs/rbf0.md 9.6 lists the refusals. For attribute counts it refuses "an element with more attribute records than its attribute count" and "an element short of its attribute count with a value in its content", because that value would decode as an attribute.

rbf0_tree._attach sets attribute_order_violation in two cases:

  • a value record arrives as an attribute after content started (a real attribute after content);
  • text or a child element arrives while the attribute count is not reached yet (a short count).

The encoder refused every flagged element as "an attribute after content". An element short of its count whose content is text or a child element was therefore refused, although no attribute follows its content, no value is in it, and its bytes write back exactly. A short-count element with no content at all already encoded (test_fewer_attribute_records_than_the_count).

The encoder now refuses on the flag when an attribute record's offset comes after the first content record's, the real attribute-after-content case. It also still refuses when the records carry no offsets to tell (a tree built by hand fails closed as before). The existing check for a value in the content of a short-count element is unchanged, and rbf0_tree is untouched, so its counts and reports stay the same.

Measured corpus effect: none. 9.6 found no such element among the 1,263 data.rpf resources, and the only refusals there are the 23 invalid-UTF-8 ones. This is the encoder agreeing with its documented rule.

Different topic from #1574 (same files); the two merge cleanly.

Tested

Windows 11, Python 3.14.7, synthetic RBF0 streams only:

  • python -I tests/test_rbf0_encode.py: 37 tests OK. test_fewer_attribute_records_than_the_count now also takes a root with attrs=2, one int attribute, then text or a child element:
    • the tree is ok and flagged;
    • the encoder returns the original bytes, where main refuses both;
    • with the record offsets removed it refuses with order.
  • test_attribute_after_content (a value after text with a short count) still refuses with order. tests/test_rbf0_tree.py OK.
  • python -m compileall; scripts/check_no_game_data.py on both files.

GPUs tested: n/a (CPU-only tool)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

🤖 Generated with Claude Code


🔄 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/2386 **Author:** [@syfyra](https://github.com/syfyra) **Created:** 11/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rbf0-encode-short-count-content` --- ### 📝 Commits (1) - [`4f1ca18`](https://github.com/ubiquitarianism/leonida/commit/4f1ca189643e738bf7b4c72a557f49d474fadc5d) rbf0_encode: write back a short-count element with text or child content (RBF0-ENCODE-SHORT-COUNT-CONTENT) ### 📊 Changes **2 files changed** (+23 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_rbf0_encode.py` (+15 -0) 📝 `tools/rbf0_encode.py` (+8 -1) </details> ### 📄 Description Claimed in the coordination issue as: RBF0-ENCODE-SHORT-COUNT-CONTENT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7198218440) ### What and why `tools/rbf0_encode.py` writes an `rbf0_tree.py` document back to bytes and fails closed. `docs/rbf0.md` 9.6 lists the refusals. For attribute counts it refuses "an element with more attribute records than its attribute count" and "an element short of its attribute count **with a value in its content**", because that value would decode as an attribute. `rbf0_tree._attach` sets `attribute_order_violation` in two cases: - a value record arrives as an attribute after content started (a real attribute after content); - text or a child element arrives while the attribute count is not reached yet (a short count). The encoder refused every flagged element as "an attribute after content". An element short of its count whose content is text or a child element was therefore refused, although no attribute follows its content, no value is in it, and its bytes write back exactly. A short-count element with no content at all already encoded (`test_fewer_attribute_records_than_the_count`). The encoder now refuses on the flag when an attribute record's offset comes after the first content record's, the real attribute-after-content case. It also still refuses when the records carry no offsets to tell (a tree built by hand fails closed as before). The existing check for a value in the content of a short-count element is unchanged, and `rbf0_tree` is untouched, so its counts and reports stay the same. Measured corpus effect: none. 9.6 found no such element among the 1,263 `data.rpf` resources, and the only refusals there are the 23 invalid-UTF-8 ones. This is the encoder agreeing with its documented rule. Different topic from #1574 (same files); the two merge cleanly. ### Tested Windows 11, Python 3.14.7, synthetic RBF0 streams only: - `python -I tests/test_rbf0_encode.py`: 37 tests OK. `test_fewer_attribute_records_than_the_count` now also takes a root with `attrs=2`, one int attribute, then text or a child element: - the tree is `ok` and flagged; - the encoder returns the original bytes, where `main` refuses both; - with the record offsets removed it refuses with `order`. - `test_attribute_after_content` (a value after text with a short count) still refuses with `order`. `tests/test_rbf0_tree.py` OK. - `python -m compileall`; `scripts/check_no_game_data.py` on both files. GPUs tested: n/a (CPU-only tool) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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#2386
No description provided.