[PR #1542] spirv_interface: validate outer array length, initializer ID, struct/member and stage decorations (SPIRV-INTERFACE-DECORATION-VALIDATION) #1571

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

📋 Pull Request Information

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

Base: main ← Head: fix/spirv-interface-decoration-validation


📝 Commits (1)

  • a0996d0 spirv_interface: validate outer array length, initializer ID, struct/member and stage decorations

📊 Changes

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

View changed files

📝 tests/test_spirv_interface.py (+138 -0)
📝 tools/spirv_interface.py (+57 -9)

📄 Description

What changed

  • Outer per-vertex / per-primitive array length validation (tools/spirv_interface.py:varying_type): call array_count(args[1]) before unwrapping the outer OpTypeArray on GS inputs, MS outputs, and PS PerVertexKHR inputs so zero, negative, non-integer, or undefined length constants raise InterfaceError instead of passing silently.
  • OpVariable initializer ID validation (tools/spirv_interface.py:read_instruction): validate the optional 4th operand (Initializer) with require_id() when present.
  • Decoration group target check (tools/spirv_interface.py:apply_decoration_groups): reject OpMemberDecorate targeting a DecorationGroup ID.
  • Struct-type decorations and out-of-range member indices (tools/spirv_interface.py:shape, declaration):
    • Track decorated member indices per struct and raise InterfaceError if any member decoration index is >= len(members) on a top-level or nested interface struct.
    • Check Patch / PassthroughNV on top-level and nested struct types themselves (not only on variables and members), and propagate PerPrimitiveEXT from a top-level interface struct type to its members.
  • Stage/storage rules for Index, PerPrimitiveEXT, and PerVertexKHR (tools/spirv_interface.py:address, declaration):
    • Reject Index on variables/members outside fragment (ps) outputs.
    • Reject PerPrimitiveEXT outside mesh (ms) outputs and fragment (ps) inputs.
    • Reject PerVertexKHR combined with PerPrimitiveEXT on the same varying, and reject PerVertexKHR on struct types or members.
  • Tests (tests/test_spirv_interface.py): added 5 synthetic binary SPIR-V regression tests (23 assertions) covering every check above.

Claimed in the coordination issue as:

SPIRV-INTERFACE-DECORATION-VALIDATION (#14 reached GitHub's 2,500-comment cap with no successor coordination issue open yet; checked #14 and open PRs — 0 claims and 0 open PRs touch tools/spirv_interface.py)

How it was tested

  • python3 -I -W error tests/test_spirv_interface.py: 48/48 passed (0 warnings).
  • python3 -I tests/test_spirv_interface_extra.py: 3/3 passed.
  • python3 -I tests/test_shader_link_check.py: 51/51 passed.
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • python3 -I scripts/check_no_game_data.py tools/spirv_interface.py tests/test_spirv_interface.py: passed.
  • python3 -m compileall -q tools/spirv_interface.py tests/test_spirv_interface.py: passed.
  • Mutation check against unpatched main:tools/spirv_interface.py: all 5 new tests fail (FAILED (failures=23)), all 43 baseline tests pass.

Metadata

  • AI-assisted: yes
  • GPUs tested: none (CPU-only synthetic SPIR-V binary reflection unit tests on macOS arm64; no game files used)

🔄 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/1542 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/spirv-interface-decoration-validation` --- ### 📝 Commits (1) - [`a0996d0`](https://github.com/ubiquitarianism/leonida/commit/a0996d0b076db01d603c189298cbbd8434d2b2e4) spirv_interface: validate outer array length, initializer ID, struct/member and stage decorations ### 📊 Changes **2 files changed** (+195 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_spirv_interface.py` (+138 -0) 📝 `tools/spirv_interface.py` (+57 -9) </details> ### 📄 Description ## What changed - **Outer per-vertex / per-primitive array length validation (`tools/spirv_interface.py:varying_type`)**: call `array_count(args[1])` before unwrapping the outer `OpTypeArray` on GS inputs, MS outputs, and PS `PerVertexKHR` inputs so zero, negative, non-integer, or undefined length constants raise `InterfaceError` instead of passing silently. - **`OpVariable` initializer ID validation (`tools/spirv_interface.py:read_instruction`)**: validate the optional 4th operand (`Initializer`) with `require_id()` when present. - **Decoration group target check (`tools/spirv_interface.py:apply_decoration_groups`)**: reject `OpMemberDecorate` targeting a `DecorationGroup` ID. - **Struct-type decorations and out-of-range member indices (`tools/spirv_interface.py:shape`, `declaration`)**: - Track decorated member indices per struct and raise `InterfaceError` if any member decoration index is `>= len(members)` on a top-level or nested interface struct. - Check `Patch` / `PassthroughNV` on top-level and nested struct types themselves (not only on variables and members), and propagate `PerPrimitiveEXT` from a top-level interface struct type to its members. - **Stage/storage rules for `Index`, `PerPrimitiveEXT`, and `PerVertexKHR` (`tools/spirv_interface.py:address`, `declaration`)**: - Reject `Index` on variables/members outside fragment (`ps`) outputs. - Reject `PerPrimitiveEXT` outside mesh (`ms`) outputs and fragment (`ps`) inputs. - Reject `PerVertexKHR` combined with `PerPrimitiveEXT` on the same varying, and reject `PerVertexKHR` on struct types or members. - **Tests (`tests/test_spirv_interface.py`)**: added 5 synthetic binary SPIR-V regression tests (23 assertions) covering every check above. ## Claimed in the coordination issue as: `SPIRV-INTERFACE-DECORATION-VALIDATION` (#14 reached GitHub's 2,500-comment cap with no successor coordination issue open yet; checked #14 and open PRs — 0 claims and 0 open PRs touch `tools/spirv_interface.py`) ## How it was tested - `python3 -I -W error tests/test_spirv_interface.py`: 48/48 passed (0 warnings). - `python3 -I tests/test_spirv_interface_extra.py`: 3/3 passed. - `python3 -I tests/test_shader_link_check.py`: 51/51 passed. - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. - `python3 -I scripts/check_no_game_data.py tools/spirv_interface.py tests/test_spirv_interface.py`: passed. - `python3 -m compileall -q tools/spirv_interface.py tests/test_spirv_interface.py`: passed. - Mutation check against unpatched `main:tools/spirv_interface.py`: all 5 new tests fail (`FAILED (failures=23)`), all 43 baseline tests pass. ## Metadata - AI-assisted: yes - GPUs tested: none (CPU-only synthetic SPIR-V binary reflection unit tests on macOS arm64; no game files used) --- <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#1571
No description provided.