Skip to content

rbf0_tree.py: carved files sharing an offset each decode, and a failed export keeps the old report - #997

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
BBareth:fix/rbf0_tree-34-35
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
BBareth:fix/rbf0_tree-34-35

Conversation

@BBareth

@BBareth BBareth commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claim: #634 (comment) (new BUILD item)

Bug. Two problems in rbf0_tree.py:

  • In a carve folder, _rows() built by_offset = {offset: path}, so two files with the same leading hex offset (000000000100-left.bin and 000000000100-right.bin) both read the last one. Both rows decoded as RootB.
  • write_json() opened the output with "w" before serializing. A valid but very deep tree (depth 600) raised RecursionError in json.dump, leaving the previous report truncated, and the run ended in a traceback.

Fix. - Each row reads the file it was listed from, os.path.join(source, row["name"]).

  • write_json() writes to a temporary file in the output's folder and os.replaces it into place. On any failure the temporary file is removed and the old report stays.
  • main() reports a RecursionError (tree exceeds the export depth limit) or an OSError from the writes as one stderr line naming the path, with exit 1.
  • Argument errors and successful runs are unchanged.

Tested. Two new tests in tests/test_rbf0_tree.py:

  • test_duplicate_offsets_keep_each_source: the two files must decode as RootA and RootB.
  • test_deep_tree_preserves_existing_json: a depth-600 tree must leave the existing report byte-identical, with exit 1 and one stderr line.

python -I tests/test_rbf0_tree.py gives 28 passed. Against main's tool both new tests fail. python -m compileall -q make_game.py tools tests passes. Python 3.12.15 on macOS arm64. CPU only, synthetic inputs, no game data. No GPU involved.

AI-assisted (Codex wrote the change, reviewed and re-tested with Claude Code).

Checklist

  • No game data, keys or decryption, including in logs or reports.
  • Translator contract is inapplicable to this change.

🤖 Generated with Claude Code

…d export keeps the old report

_rows() mapped each carve-folder file's offset to its path, so two files with
the same leading hex offset (000000000100-left.bin, -right.bin) both read the
last one. Rows now read the file they were built from.

write_json() opened the report for writing before serializing, so a tree too
deep to serialize (RecursionError) left the previous report truncated. The
JSON is written to a temporary file in the same folder and renamed in; a too
deep tree or an unwritable output is one line on stderr, exit 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kapitche

Copy link
Copy Markdown
Contributor

Tested 7ddb343 on Linux (WSL2 Ubuntu), Python 3.12, CPU only: pass, one question

  • pytest tests/test_rbf0_tree.py: 28 passed, 10 subtests
  • Negative control: with tools/rbf0_tree.py from main, 2 fail.
  • Code read: rows now read os.path.join(source, row["name"]), which fixes the shared-offset case.

The question: write_json now goes through NamedTemporaryFile + os.replace, which creates the report 0600. With umask 022 I get 0o600 from write_json, against 0o644 from a plain open(..., 'w'), so a replaced report becomes owner-only. #750 and #728 added a chmod for exactly this. If the report is ever shared (a server, another user), the same fix applies here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BBareth

BBareth commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

@kapitche good catch, thanks. In f8bd330 the report gets chmoded before the swap, with the same rule as rtti_scan._report_mode (#750): the replaced report's bits, or 0666 minus the umask for a new one. New test_report_keeps_the_usual_permission_bits (skipped on Windows) checks umask 022 → 0644, and that an existing 0640 report stays 0640. python -I tests/test_rbf0_tree.py gives 29 passed.

@ItsNotRexed
ItsNotRexed merged commit 286478a into ItsNotRexed:main Nov 22, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants