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

Merged
leonida/mandy
kirigayakazima merged 1 commit from fix/vs-input-survey-safe-paths-and-atomic-json into main 2026-11-28 11:44:36 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-25 11:43:29 +00:00

Claimed in the coordination issue as: VS-INPUT-SURVEY-SAFE-PATHS-AND-ATOMIC-JSON https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161333334

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)
Claimed in the coordination issue as: VS-INPUT-SURVEY-SAFE-PATHS-AND-ATOMIC-JSON https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161333334 ### 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)
PierreEbele commented 2026-11-25 18:40:36 +00:00

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

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
sodove commented 2026-11-28 11:27:52 +00:00

#1767 | head 51e47a68a4e167417537421eeb1be35412d075e8 | python3 -m pytest -q -rA tests/test_vs_input_survey.py, py -3.12 -I tests/test_vs_input_survey.py -v | red: 1 failed (Linux) / 11 failed checks (Windows) | green: 1 passed (Linux) / standalone script passed (0 failed checks) (Windows) | Red → green

The native Windows script exercised real read-only JSON file handling, in addition to the simulated failures. It reported no failed checks after merging.

Copied the PR tests onto clean main 4a54aedcb6b66525e0c9f72a6ea10263337c9141 for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native Windows used Python 3.12.10. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. Batch claim.

#1767 | head `51e47a68a4e167417537421eeb1be35412d075e8` | `python3 -m pytest -q -rA tests/test_vs_input_survey.py`, `py -3.12 -I tests/test_vs_input_survey.py -v` | red: 1 failed (Linux) / 11 failed checks (Windows) | green: 1 passed (Linux) / standalone script passed (0 failed checks) (Windows) | **Red → green** The native Windows script exercised real read-only JSON file handling, in addition to the simulated failures. It reported no failed checks after merging. Copied the PR tests onto clean main `4a54aedcb6b66525e0c9f72a6ea10263337c9141` for the baseline, then merged that main into the recorded PR head and reran those files. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native Windows used Python 3.12.10. Unittest failure/error counts include subtests where applicable. AI-assisted with OpenAI Codex. [Batch claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7238450840).
DadaCap commented 2026-11-28 11:44:38 +00:00

Merged, thank you @kirigayakazima! This PR (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)) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch.

AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.

Merged, thank you @kirigayakazima! This PR (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)) passed its own tests with main merged in during sodove's verification of this shader batch, so it went in with the batch. AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.
Sign in to join this conversation.
No description provided.