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

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

📋 Pull Request Information

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

Base: main ← Head: fix/shader-stats-validation-and-cli


📝 Commits (1)

  • ec6dffd shader_stats: reject traversal shader names, support UTF-8 BOM, and harden CLI/number guards

📊 Changes

2 files changed (+113 additions, -9 deletions)

View changed files

📝 scripts/shader_stats.py (+25 -9)
📝 tests/test_shader_stats.py (+88 -0)

📄 Description

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).

🔄 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/1607 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/shader-stats-validation-and-cli` --- ### 📝 Commits (1) - [`ec6dffd`](https://github.com/ubiquitarianism/leonida/commit/ec6dffd32d692a7b13572ee2bc42e26978013516) shader_stats: reject traversal shader names, support UTF-8 BOM, and harden CLI/number guards ### 📊 Changes **2 files changed** (+113 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `scripts/shader_stats.py` (+25 -9) 📝 `tests/test_shader_stats.py` (+88 -0) </details> ### 📄 Description 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`). --- <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#1622
No description provided.