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

Open
opened 2026-11-26 20:22:02 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1655
Author: @PierreEbele
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: text-tables-source-file-guard


📝 Commits (1)

  • e231d2c text_tables: refuse a report that would overwrite a file read from a source directory

📊 Changes

2 files changed (+64 additions, -0 deletions)

View changed files

📝 tests/test_text_tables.py (+40 -0)
📝 tools/text_tables.py (+24 -0)

📄 Description

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


🔄 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/1655 **Author:** [@PierreEbele](https://github.com/PierreEbele) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `text-tables-source-file-guard` --- ### 📝 Commits (1) - [`e231d2c`](https://github.com/ubiquitarianism/leonida/commit/e231d2cb5f9ae1a5256b6ab8a60288503a16467c) text_tables: refuse a report that would overwrite a file read from a source directory ### 📊 Changes **2 files changed** (+64 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_text_tables.py` (+40 -0) 📝 `tools/text_tables.py` (+24 -0) </details> ### 📄 Description ## 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) --- <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#1669
No description provided.