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

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/420
Author: @tahffo68hk-hash
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/rt-rootsig-parse-pack


📝 Commits (1)

  • c7ff7f0 root_signature: prevent u32 offset wrap in parse_rts0_payload and validate param type in pack_stage (RT-ROOTSIG-PARSE-PACK)

📊 Changes

2 files changed (+38 additions, -5 deletions)

View changed files

📝 runtime/src/root_signature.cpp (+11 -5)
📝 runtime/test/root_signature_test.cpp (+27 -0)

📄 Description

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

🔄 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/420 **Author:** [@tahffo68hk-hash](https://github.com/tahffo68hk-hash) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rt-rootsig-parse-pack` --- ### 📝 Commits (1) - [`c7ff7f0`](https://github.com/ubiquitarianism/leonida/commit/c7ff7f066725d0b70315874bfabeb79e5d83de81) root_signature: prevent u32 offset wrap in parse_rts0_payload and validate param type in pack_stage (RT-ROOTSIG-PARSE-PACK) ### 📊 Changes **2 files changed** (+38 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/root_signature.cpp` (+11 -5) 📝 `runtime/test/root_signature_test.cpp` (+27 -0) </details> ### 📄 Description 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> --- <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#472
No description provided.