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

Merged
PierreEbele merged 1 commit from upstream-pr/1655 into main 2026-11-28 10:43:36 +00:00
PierreEbele commented 2026-11-25 07:19:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T07:19:02Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5486962692 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1655). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T07:19:02Z. --- ## 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)
whoalin1 commented 2026-11-25 11:12:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T11:12:50Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7160746303 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1655#issuecomment-7160746303). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T11:12:50Z. --- 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.
MoonEyes commented 2026-11-28 10:43:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:43:33Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238081328 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1655#issuecomment-7238081328). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:43:33Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1655
No description provided.