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

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

@⁠tahffo68hk-hash on GitHub · 2026-11-24 04:54 UTC · original
tahffo68hk-hash:fix/rt-rootsig-parse-pack → main · +38 −5 · 2 files · 1 commits · open

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)。
**@⁠tahffo68hk-hash** on GitHub · 2026-11-24 04:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/420) `tahffo68hk-hash:fix/rt-rootsig-parse-pack` → `main` · +38 −5 · 2 files · 1 commits · open 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>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:59:11 +00:00
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-24 10:37 UTC · original

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.

**@⁠Oliwettoo** on GitHub · 2026-11-24 10:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/420#issuecomment-7129033817) 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.
This pull request has changes conflicting with the target branch.
  • runtime/src/root_signature.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/420/head:github-bot/gh-420'
git switch 'github-bot/gh-420'

Merge

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