Skip to content

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

Merged
MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
PierreEbele:text-tables-source-file-guard
Nov 28, 2026
Merged

MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
PierreEbele:text-tables-source-file-guard

Conversation

@PierreEbele

Copy link
Copy Markdown
Contributor

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

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

@whoalin1

Copy link
Copy Markdown
Contributor

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.

…source directory

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 <noreply@anthropic.com>
@PierreEbele
PierreEbele force-pushed the text-tables-source-file-guard branch from 73d744e to e231d2c Compare November 26, 2026 15:58
@MoonEyes

Copy link
Copy Markdown
Collaborator

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)

@MoonEyes
MoonEyes merged commit 84294b6 into ProjectLeonida:main Nov 28, 2026
5 of 8 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