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

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

@⁠IlyassRS3 on GitHub · 2026-11-25 05:48 UTC · original
IlyassRS3:fix/shader-stats-validation-and-cli → main · +113 −9 · 2 files · 1 commits · open

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).
**@⁠IlyassRS3** on GitHub · 2026-11-25 05:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1607) `IlyassRS3:fix/shader-stats-validation-and-cli` → `main` · +113 −9 · 2 files · 1 commits · open 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`).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:57:53 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 05:48 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 05:48 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1607#pullrequestreview-6052482082) · **reviewed** 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.
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/1607/head:github-bot/gh-1607'
git switch 'github-bot/gh-1607'

Merge

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