text_tables: refuse a report that would overwrite a file read from a source directory (TEXT-TABLES-SOURCE-FILE-GUARD) #1655

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

@⁠PierreEbele on GitHub · 2026-11-25 07:19 UTC · original
PierreEbele:text-tables-source-file-guard → main · +64 −0 · 2 files · 1 commits · open

What changes

tools/text_tables.py checked --dialogue/--tables/--strings only against the named sources and a carve's index.json. But blobs() also reads every file below a plain source directory and every carved <offset:012x>.bin/.bk2 beside index.json, so a report path naming one of those files was read as input and then replaced by the CSV, with exit 0:

$ python3 tools/text_tables.py src --tables src/notes.txt   # on main
0 string tables (); 0 dialogue keys, 0 lines; lines with text:
$ cat src/notes.txt
source,offset,lang,guess,archive,group,strings,resolved

The tool now refuses such a report before anything is written (--tables would overwrite the input src/notes.txt, exit 2):

  • plain directory: the report is compared (via report_paths.same_report_path) with every file below the source, only when the report already exists;
  • carve directory: gamedata_index.carved_stream() is reused, the same guard gamedata_index.py applies to its own reports (so the case/hard-link hardening proposed in #1578 applies here too).

A new report inside a source directory is still written: it is created after the scan, so it was never an input (covered by a test).

The new check sits right after the existing index.json check; it does not touch the lines changed by #1228, #738 or #818.

Tests

Run in a sandbox (Linux, no network):

  • tests/test_text_tables.py: 36 OK (1 Windows-only skip) on this branch; with the new tests on main's tool, test_report_cannot_replace_a_file_read_from_a_source_directory and test_report_cannot_replace_a_carved_stream fail.
  • test_report_paths.py, test_report_path_case.py, test_missing_input_exit_codes.py, test_gamedata_index.py: OK.
  • scripts/check_no_game_data.py tools/text_tables.py tests/test_text_tables.py: clean. Synthetic fixtures only, no game data.

Claimed in the coordination issue as: TEXT-TABLES-SOURCE-FILE-GUARD

AI-assisted.

🤖 Generated with Claude Code

**@⁠PierreEbele** on GitHub · 2026-11-25 07:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1655) `PierreEbele:text-tables-source-file-guard` → `main` · +64 −0 · 2 files · 1 commits · open ## What changes `tools/text_tables.py` checked `--dialogue`/`--tables`/`--strings` only against the named sources and a carve's `index.json`. But `blobs()` also reads every file below a plain source directory and every carved `<offset:012x>.bin`/`.bk2` beside `index.json`, so a report path naming one of those files was read as input and then replaced by the CSV, with exit 0: ``` $ python3 tools/text_tables.py src --tables src/notes.txt # on main 0 string tables (); 0 dialogue keys, 0 lines; lines with text: $ cat src/notes.txt source,offset,lang,guess,archive,group,strings,resolved ``` The tool now refuses such a report before anything is written (`--tables would overwrite the input src/notes.txt`, exit 2): - plain directory: the report is compared (via `report_paths.same_report_path`) with every file below the source, only when the report already exists; - carve directory: `gamedata_index.carved_stream()` is reused, the same guard `gamedata_index.py` applies to its own reports (so the case/hard-link hardening proposed in #1578 applies here too). A *new* report inside a source directory is still written: it is created after the scan, so it was never an input (covered by a test). The new check sits right after the existing `index.json` check; it does not touch the lines changed by #1228, #738 or #818. ## Tests Run in a sandbox (Linux, no network): - `tests/test_text_tables.py`: 36 OK (1 Windows-only skip) on this branch; with the new tests on main's tool, `test_report_cannot_replace_a_file_read_from_a_source_directory` and `test_report_cannot_replace_a_carved_stream` fail. - `test_report_paths.py`, `test_report_path_case.py`, `test_missing_input_exit_codes.py`, `test_gamedata_index.py`: OK. - `scripts/check_no_game_data.py tools/text_tables.py tests/test_text_tables.py`: clean. Synthetic fixtures only, no game data. Claimed in the coordination issue as: TEXT-TABLES-SOURCE-FILE-GUARD AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The output guard compared --dialogue/--tables/--strings only with the
named sources and a carve's index.json. blobs() also reads every file
below a plain source directory and every carved <offset>.bin/.bk2 beside
index.json, so `text_tables.py src --tables src/notes.txt` read the file
and then replaced it with the CSV (exit 0). Refuse such a report before
anything is written; carved streams go through gamedata_index's
carved_stream(). A new report inside a source directory is still allowed:
it is written after the scan, so it was never an input.

AI-assisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:37 +00:00
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 11:12 UTC · original

Independent verification (Windows, Python 3.11.9): input_under() reuses gamedata_index.carved_stream() for carve dirs and walks plain dirs via same_report_path only when the report already exists — wired for all three outputs, ap.error exit 2 before writes. test_text_tables.py 36 OK; neighbors report_paths/report_path_case/missing_input_exit_codes/gamedata_index all OK; manual probes correct (existing file in source dir -> exit 2 preserved; new file -> written). check_no_game_data clean. Minor non-blocking: TOCTOU window between pre-scan and write; a report naming a directory inside the source is allowed (fails later at write). AI-assisted verification.

**@⁠whoalin1** on GitHub · 2026-11-25 11:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1655#issuecomment-7160746303) Independent verification (Windows, Python 3.11.9): `input_under()` reuses `gamedata_index.carved_stream()` for carve dirs and walks plain dirs via `same_report_path` only when the report already exists — wired for all three outputs, `ap.error` exit 2 before writes. `test_text_tables.py` 36 OK; neighbors report_paths/report_path_case/missing_input_exit_codes/gamedata_index all OK; manual probes correct (existing file in source dir -> exit 2 preserved; new file -> written). check_no_game_data clean. Minor non-blocking: TOCTOU window between pre-scan and write; a report naming a directory inside the source is allowed (fails later at write). AI-assisted verification.
github-bot force-pushed github-bot/gh-1655 from 73d744e4e6 to e231d2cb5f 2026-11-26 16:01:25 +00:00 Compare
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/1655/head:github-bot/gh-1655'
git switch 'github-bot/gh-1655'

Merge

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