vs_input_survey: validate index.json filenames, accept UTF-8 BOM, guard inputs, and publish --json atomically (VS-INPUT-SURVEY-SAFE-PATHS-AND-ATOMIC-JSON) #1767

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

@⁠kirigayakazima on GitHub · 2026-11-25 11:43 UTC · original
kirigayakazima:fix/vs-input-survey-safe-paths-and-atomic-json → main · +155 −16 · 2 files · 1 commits · open

Claimed in the coordination issue as: VS-INPUT-SURVEY-SAFE-PATHS-AND-ATOMIC-JSON #1608

What and why

Hardens scripts/vs_input_survey.py:

  1. Validate index.json file entries against path traversal: Validate every VS entry's file field via _safe_shader_stem (rejecting /, \, :, drive prefixes, control characters, ., and ..) before resolving <dxbc>/disasm/<stem>.s.
  2. Accept UTF-8 BOM in index.json: Open index.json with encoding="utf-8-sig" so BOM files written by PowerShell/Windows editors load cleanly.
  3. Full same_report_path & directory guard for --json: Replace bare os.path.samefile(a.json, index_path) with same_report_path across index.json, <dxbc>, and every surveyed <dxbc>/disasm/<stem>.s, and refuse existing directory targets cleanly on stderr (exit 2).
  4. Atomic --json write with Windows read-only cleanup: Stage JSON in the destination directory, apply published_mode, publish via replace_retry, and restore 0o600 before unlinking on failure so failed or read-only writes preserve any previous JSON file intact and leave no .vs_input_survey-*.tmp files.

Adds synthetic regression checks in tests/test_vs_input_survey.py.

Tested

Windows 11 x64 (10.0.26100), Python 3.14.7, CPU only, synthetic dxbc fixtures only (no game files). Commit 51e47a68a4e167417537421eeb1be35412d075e8.

  • python -I tests/test_vs_input_survey.py:
    • against main (bcaa13da) with the updated test file: FAILED (11 failures) (path traversal accepted, UTF-8 BOM rejected, --json directory/.s overwrites uncaught, mid-write error wipes existing --json);
    • with the fix: OK (0 failures).
  • python -I tests/test_vs_input_survey_rbw.py -v: 12 tests, OK.
  • python -I tests/test_ci_registration.py: 16 tests, OK.
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py scripts/vs_input_survey.py tests/test_vs_input_survey.py, python -m compileall -q scripts tools tests, git diff --check: exit 0.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)
**@⁠kirigayakazima** on GitHub · 2026-11-25 11:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1767) `kirigayakazima:fix/vs-input-survey-safe-paths-and-atomic-json` → `main` · +155 −16 · 2 files · 1 commits · open Claimed in the coordination issue as: VS-INPUT-SURVEY-SAFE-PATHS-AND-ATOMIC-JSON https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ### What and why Hardens `scripts/vs_input_survey.py`: 1. **Validate `index.json` `file` entries against path traversal**: Validate every VS entry's `file` field via `_safe_shader_stem` (rejecting `/`, `\`, `:`, drive prefixes, control characters, `.`, and `..`) before resolving `<dxbc>/disasm/<stem>.s`. 2. **Accept UTF-8 BOM in `index.json`**: Open `index.json` with `encoding="utf-8-sig"` so BOM files written by PowerShell/Windows editors load cleanly. 3. **Full `same_report_path` & directory guard for `--json`**: Replace bare `os.path.samefile(a.json, index_path)` with `same_report_path` across `index.json`, `<dxbc>`, and every surveyed `<dxbc>/disasm/<stem>.s`, and refuse existing directory targets cleanly on stderr (exit `2`). 4. **Atomic `--json` write with Windows read-only cleanup**: Stage JSON in the destination directory, apply `published_mode`, publish via `replace_retry`, and restore `0o600` before unlinking on failure so failed or read-only writes preserve any previous JSON file intact and leave no `.vs_input_survey-*.tmp` files. Adds synthetic regression checks in `tests/test_vs_input_survey.py`. ### Tested Windows 11 x64 (`10.0.26100`), Python `3.14.7`, CPU only, synthetic `dxbc` fixtures only (no game files). Commit `51e47a68a4e167417537421eeb1be35412d075e8`. - `python -I tests/test_vs_input_survey.py`: - against `main` (`bcaa13da`) with the updated test file: **FAILED (11 failures)** (path traversal accepted, UTF-8 BOM rejected, `--json` directory/`.s` overwrites uncaught, mid-write error wipes existing `--json`); - with the fix: **OK (0 failures)**. - `python -I tests/test_vs_input_survey_rbw.py -v`: **12 tests, OK**. - `python -I tests/test_ci_registration.py`: **16 tests, OK**. - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py scripts/vs_input_survey.py tests/test_vs_input_survey.py`, `python -m compileall -q scripts tools tests`, `git diff --check`: exit `0`. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator change)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:04:12 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 18:40 UTC · original

Reviewed 51e47a68a: vs_input_survey filename validation, BOM handling, --json guards and atomic publish. Ran on this tree and origin/main: python -I tests/test_vs_input_survey.py (all checks pass; the new checks fail on main), test_vs_input_survey_rbw.py, test_text_write_line_endings.py, pytest tests/test_vs_input_survey.py, check_no_game_data.py on both changed files, plus a probe of the old behaviour (../../x.dxbc traversal surveys a file outside dxbc; --json equal to a surveyed .s overwrites it) and the new refusals. No live staging files remain; destination mode is preserved. The Windows-only test branches did not run. No findings.

AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 18:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1767#issuecomment-7171238863) Reviewed 51e47a68a: vs_input_survey filename validation, BOM handling, `--json` guards and atomic publish. Ran on this tree and origin/main: `python -I tests/test_vs_input_survey.py` (all checks pass; the new checks fail on main), `test_vs_input_survey_rbw.py`, `test_text_write_line_endings.py`, `pytest tests/test_vs_input_survey.py`, `check_no_game_data.py` on both changed files, plus a probe of the old behaviour (`../../x.dxbc` traversal surveys a file outside dxbc; `--json` equal to a surveyed `.s` overwrites it) and the new refusals. No live staging files remain; destination mode is preserved. The Windows-only test branches did not run. No findings. AI-assisted review. **Recommendation:** Merge
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/1767/head:github-bot/gh-1767'
git switch 'github-bot/gh-1767'

Merge

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