[PR #1767] 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) #1779

Open
opened 2026-11-26 21:18:55 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/vs-input-survey-safe-paths-and-atomic-json


📝 Commits (1)

  • 51e47a6 vs_input_survey: validate index.json filenames, accept UTF-8 BOM, guard all inputs, and write --json atomically

📊 Changes

2 files changed (+155 additions, -16 deletions)

View changed files

📝 scripts/vs_input_survey.py (+83 -16)
📝 tests/test_vs_input_survey.py (+72 -0)

📄 Description

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)

🔄 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/1767 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/vs-input-survey-safe-paths-and-atomic-json` --- ### 📝 Commits (1) - [`51e47a6`](https://github.com/ubiquitarianism/leonida/commit/51e47a68a4e167417537421eeb1be35412d075e8) vs_input_survey: validate index.json filenames, accept UTF-8 BOM, guard all inputs, and write --json atomically ### 📊 Changes **2 files changed** (+155 additions, -16 deletions) <details> <summary>View changed files</summary> 📝 `scripts/vs_input_survey.py` (+83 -16) 📝 `tests/test_vs_input_survey.py` (+72 -0) </details> ### 📄 Description 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) --- <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#1779
No description provided.