root_signature: guard u32 offset wrap in RTS0 constants and validate param type in pack_stage (RT-ROOTSIG-PARSE-PACK) #420

Closed
tahffo68hk-hash wants to merge 1 commit from upstream-pr/420 into main
tahffo68hk-hash commented 2026-11-24 04:54:20 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tahffo68hk-hash on 2026-11-24T04:54:20Z.


Claimed in the coordination issue as: RT-ROOTSIG-PARSE-PACK

Problem

Two validation gaps in runtime/src/root_signature.cpp:

  1. In parse_rts0_payload(), the Constants branch computed poff + 4 and poff + 8 in 32-bit uint32_t. A malformed RTS0 payload with poff >= 0xFFFFFFFC wrapped poff + 4 / poff + 8 to 0 / 4 instead of failing bounds checks, reading earlier header bytes (the Table and Descriptor branches already promoted poff to size_t).
  2. pack_stage() omitted the ParamType validity check that pack() performs, silently accepting unknown parameter types and returning ok = true.

Fix

  • Promote poff to size_t before adding field offsets in parse_rts0_payload() (both Constants and Descriptor branches).
  • Validate p.type in pack_stage() identically to pack().
  • Add regression tests in runtime/test/root_signature_test.cpp covering both cases.

Verification

  • Built with MSVC 19.44 + Ninja (-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF) on Windows 11.
  • root_signature_test.exe -> exit code 0, 0 failures (no game files).
  • AI-assisted: Yes (Antigravity).
中文翻译

在协调帖 #14 中认领的 ID:RT-ROOTSIG-PARSE-PACK

问题描述

runtime/src/root_signature.cpp 存在两处校验缺陷:

  1. parse_rts0_payload() 处理 Constants 参数时在 32 位 uint32_t 上计算 poff + 4 与 poff + 8,当畸形 RTS0 载荷中 poff >= 0xFFFFFFFC 时会发生 32 位回绕,误读头部字节而非触发越界拦截。
  2. pack_stage() 遗漏了 pack() 中的 p.type 合法性校验,对未知参数类型静默返回 ok = true。

修复方案

  • 在 parse_rts0_payload() 中先将 poff 提升为 size_t 再加字段偏移。
  • 在 pack_stage() 中补齐与 pack() 一致的 p.type 校验。
  • 在 runtime/test/root_signature_test.cpp 中补充两项回归测试。

验证结果

  • Windows 11 + MSVC 19.44 + Ninja 编译并运行 root_signature_test.exe,0 失败(无游戏文件)。
  • AI 辅助:是(Antigravity)。
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5466326735 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/420). Originally posted by [tahffo68hk-hash](https://github.com/tahffo68hk-hash) on 2026-11-24T04:54:20Z. --- Claimed in the coordination issue as: `RT-ROOTSIG-PARSE-PACK` ## Problem Two validation gaps in `runtime/src/root_signature.cpp`: 1. In `parse_rts0_payload()`, the `Constants` branch computed `poff + 4` and `poff + 8` in 32-bit `uint32_t`. A malformed RTS0 payload with `poff >= 0xFFFFFFFC` wrapped `poff + 4` / `poff + 8` to `0` / `4` instead of failing bounds checks, reading earlier header bytes (the `Table` and `Descriptor` branches already promoted `poff` to `size_t`). 2. `pack_stage()` omitted the `ParamType` validity check that `pack()` performs, silently accepting unknown parameter types and returning `ok = true`. ## Fix - Promote `poff` to `size_t` before adding field offsets in `parse_rts0_payload()` (both `Constants` and `Descriptor` branches). - Validate `p.type` in `pack_stage()` identically to `pack()`. - Add regression tests in `runtime/test/root_signature_test.cpp` covering both cases. ## Verification - Built with MSVC 19.44 + Ninja (`-DLEONIDA_BUILD_WINDOWS_RUNTIME=OFF`) on Windows 11. - `root_signature_test.exe` -> exit code 0, 0 failures (no game files). - AI-assisted: Yes (Antigravity). <details> <summary>中文翻译</summary> 在协调帖 #14 中认领的 ID:`RT-ROOTSIG-PARSE-PACK` ## 问题描述 `runtime/src/root_signature.cpp` 存在两处校验缺陷: 1. `parse_rts0_payload()` 处理 `Constants` 参数时在 32 位 `uint32_t` 上计算 `poff + 4` 与 `poff + 8`,当畸形 RTS0 载荷中 `poff >= 0xFFFFFFFC` 时会发生 32 位回绕,误读头部字节而非触发越界拦截。 2. `pack_stage()` 遗漏了 `pack()` 中的 `p.type` 合法性校验,对未知参数类型静默返回 `ok = true`。 ## 修复方案 - 在 `parse_rts0_payload()` 中先将 `poff` 提升为 `size_t` 再加字段偏移。 - 在 `pack_stage()` 中补齐与 `pack()` 一致的 `p.type` 校验。 - 在 `runtime/test/root_signature_test.cpp` 中补充两项回归测试。 ## 验证结果 - Windows 11 + MSVC 19.44 + Ninja 编译并运行 `root_signature_test.exe`,0 失败(无游戏文件)。 - AI 辅助:是(Antigravity)。 </details>
Oliwettoo commented 2026-11-24 10:37:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Oliwettoo on 2026-11-24T10:37:45Z.


Built root_signature_test with g++ (Linux) and ran it: all checks pass with the PR. Then I ran the PR's test file against main's root_signature.cpp: only "pack_stage: unknown parameter type rejected" fails there; "constants payload offset near UINT32_MAX does not wrap" passes on current main as well. That's because the first u32_at(poff, ...) already refuses a poff past the payload, and once poff <= size - 4 the poff + 4 / poff + 8 can't wrap a uint32_t. So the size_t base change is harmless but not a fix, and that test doesn't guard anything. Suggest either dropping that part and the "offset wrap" wording in the title, or saying it's defensive only. The pack_stage type check is a real (if internal-only) guard and its test does fail on main. AI-assisted review.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7129033817 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/420#issuecomment-7129033817). Originally posted by [Oliwettoo](https://github.com/Oliwettoo) on 2026-11-24T10:37:45Z. --- Built `root_signature_test` with g++ (Linux) and ran it: all checks pass with the PR. Then I ran the PR's test file against `main`'s `root_signature.cpp`: only "pack_stage: unknown parameter type rejected" fails there; "constants payload offset near UINT32_MAX does not wrap" passes on current main as well. That's because the first `u32_at(poff, ...)` already refuses a `poff` past the payload, and once `poff <= size - 4` the `poff + 4` / `poff + 8` can't wrap a `uint32_t`. So the `size_t base` change is harmless but not a fix, and that test doesn't guard anything. Suggest either dropping that part and the "offset wrap" wording in the title, or saying it's defensive only. The `pack_stage` type check is a real (if internal-only) guard and its test does fail on main. AI-assisted review.
MoonEyes commented 2026-11-27 23:19:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-27T23:19:36Z.


Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with main (conflicting file(s): runtime/src/root_signature.cpp), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7230053276 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/420#issuecomment-7230053276). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-27T23:19:36Z. --- Hi @tahffo68hk-hash, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `runtime/src/root_signature.cpp`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
OreoFR commented 2026-11-28 21:42:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:42:43Z.


Verified by OreoFR

  • Base: main c1ecf04ed + PR head c7ff7f066
  • Test: not run (merge conflict with main)
  • Red on main: not run
  • Green with the PR: not run
  • Verdict: CONFLICT (conflicts with main in runtime/src/root_signature.cpp (1 hunk); needs a rebase, see also #2007 on the same RTS0 checks)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246215891 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/420#issuecomment-7246215891). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:42:43Z. --- **Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `c7ff7f066` - Test: not run (merge conflict with main) - Red on main: not run - Green with the PR: not run - Verdict: CONFLICT (conflicts with main in runtime/src/root_signature.cpp (1 hunk); needs a rebase, see also #2007 on the same RTS0 checks) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 16:30:09 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:30:09Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317712243 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/420#issuecomment-7317712243). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:30:09Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!420
No description provided.