shader_stats: reject traversal shader names, support UTF-8 BOM, and harden CLI/number guards (SHADER-STATS-VALIDATION-AND-CLI) #1607

Merged
leonida/mandy
quietfold merged 1 commit from fix/shader-stats-validation-and-cli into main 2026-11-28 10:36:21 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 05:48:37 +00:00

Item ID: SHADER-STATS-VALIDATION-AND-CLI (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches scripts/shader_stats.py).

What changed

  • Reject path-escaping / invalid shader names (scripts/shader_stats.py, _safe_shader_name, load_stats): previously os.path.join(disasm, name + ".s") allowed absolute paths or ../ entries in stats.csv to read .s files outside <disasm dir>. Now load_stats() validates that each row's name is a single non-empty filename stem with no path separators, drive prefix, NUL byte, . or ...
  • Accept UTF-8 BOM CSV inputs (load_stats): decode stats.csv with utf-8-sig so BOM-prefixed CSVs do not fail with missing required header column(s): name.
  • Validate <disasm dir> before matching listings (main): report <disasm dir>: not a directory instead of silently skipping every shader and exiting with "no shader is in both...".
  • Guard bool in number() and empty vlist in original(): number(True) previously crashed inside Decimal(True) with an uncaught TypeError, and an empty vlist crashed max().
  • Harden main(argv=None) option and path parsing: accept optional argv, check "--details" in argv instead of sys.argv, reject unknown single-dash flags (e.g. -d) as unknown option instead of misparsing them as positional arguments, and reject whitespace-only <stats.csv> / <disasm dir>.
  • Synthetic regression tests (tests/test_shader_stats.py): 6 new test methods covering all of the above (no game files, no GPU).

Verification

  • AI-assisted: yes
  • GPUs tested: none (CPU-only Python tool on macOS)
  • python3 -W error -I tests/test_shader_stats.py -v: 29 passed
  • python3 -W error -I tests/test_text_write_line_endings.py: passed
  • python3 -I scripts/check_no_game_data.py scripts/shader_stats.py tests/test_shader_stats.py: clean
  • python3 -m compileall -q scripts/shader_stats.py tests/test_shader_stats.py: clean
  • Mutation test (tests/test_shader_stats.py against unpatched main:scripts/shader_stats.py): 11 failures, 1 error across the 29 tests (all 6 new tests fail on unpatched main).
Item ID: `SHADER-STATS-VALIDATION-AND-CLI` (unlisted; coordination issue #14 is at GitHub's 2,500-comment cap with no open successor at submission time, and no open PR touches `scripts/shader_stats.py`). ## What changed - **Reject path-escaping / invalid shader names (`scripts/shader_stats.py`, `_safe_shader_name`, `load_stats`)**: previously `os.path.join(disasm, name + ".s")` allowed absolute paths or `../` entries in `stats.csv` to read `.s` files outside `<disasm dir>`. Now `load_stats()` validates that each row's `name` is a single non-empty filename stem with no path separators, drive prefix, NUL byte, `.` or `..`. - **Accept UTF-8 BOM CSV inputs (`load_stats`)**: decode `stats.csv` with `utf-8-sig` so BOM-prefixed CSVs do not fail with `missing required header column(s): name`. - **Validate `<disasm dir>` before matching listings (`main`)**: report `<disasm dir>: not a directory` instead of silently skipping every shader and exiting with `"no shader is in both..."`. - **Guard `bool` in `number()` and empty `vlist` in `original()`**: `number(True)` previously crashed inside `Decimal(True)` with an uncaught `TypeError`, and an empty `vlist` crashed `max()`. - **Harden `main(argv=None)` option and path parsing**: accept optional `argv`, check `"--details" in argv` instead of `sys.argv`, reject unknown single-dash flags (e.g. `-d`) as `unknown option` instead of misparsing them as positional arguments, and reject whitespace-only `<stats.csv>` / `<disasm dir>`. - **Synthetic regression tests (`tests/test_shader_stats.py`)**: 6 new test methods covering all of the above (no game files, no GPU). ## Verification - AI-assisted: yes - GPUs tested: none (CPU-only Python tool on macOS) - `python3 -W error -I tests/test_shader_stats.py -v`: **29 passed** - `python3 -W error -I tests/test_text_write_line_endings.py`: passed - `python3 -I scripts/check_no_game_data.py scripts/shader_stats.py tests/test_shader_stats.py`: clean - `python3 -m compileall -q scripts/shader_stats.py tests/test_shader_stats.py`: clean - Mutation test (`tests/test_shader_stats.py` against unpatched `main:scripts/shader_stats.py`): **11 failures, 1 error** across the 29 tests (all 6 new tests fail on unpatched `main`).
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 05:48:47 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:36:14 +00:00

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)

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)
Sign in to join this conversation.
No description provided.