mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:55:52 +01:00
[PR #2007] runtime: harden RTS0/DXBC offset checks and pre-size canonical root-signature encoding (RT-ROOT-SIGNATURE-RTS0-OFFSET-WRAP-AND-RESERVE) #2015
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#2015
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/2007
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open
Base:
main← Head:fix/rt-root-signature-rts0-offset-wrap📝 Commits (1)
2d2d645runtime: harden RTS0/DXBC offset checks and pre-size canonical root-signature encoding📊 Changes
2 files changed (+139 additions, -65 deletions)
View changed files
📝
runtime/src/root_signature.cpp(+72 -65)📝
runtime/test/root_signature_test.cpp(+67 -0)📄 Description
Claim:
RT-ROOT-SIGNATURE-RTS0-OFFSET-WRAP-AND-RESERVE(claim comment#7170207565on #1608).Problem
In
runtime/src/root_signature.cpp:uint32_toffset addition inparse_rts0_payload():dtype == 1(Constants) anddtype == 2..4(Descriptor) passedpoff + 4andpoff + 8asuint32_tbefore promoting tosize_t(unlikeTable, which already promotedstatic_cast<size_t>(poff) + 4), wrapping offsets nearUINT32_MAX.Reader::u32()andparse_rts0():pos_ + 4 > size_,off + 4 > size,static_cast<size_t>(off) + 8 > size, andstatic_cast<size_t>(off) + 8 + payload_size > sizecan wrap on 32-bitsize_t, andparse_rts0()repeated the identicaloff + 8 > sizecheck inside theRTS0branch.push_backinencode_canonical():encode_canonical()grew an unreservedstd::vector<uint8_t>one byte at a time (put_u32doing 4push_backcalls per dword).Fix
pofftosize_t pbase = static_cast<size_t>(poff)once per parameter inparse_rts0_payload()and validate payload spans with subtraction (pbase > size || need > size - pbase) forConstants,Descriptor, andTable.Reader::u32()andparse_rts0()with overflow-free subtraction checks and remove the redundantRTS0chunk-header check.encode_canonical()and write little-endian dwords directly into a single pre-sized buffer (write_u32/write_f32).runtime/test/root_signature_test.cpp(0CMakeLists.txtedits) covering wrappingpoff(0xFFFFFFFC/0xFFFFFFF8/0xFFFFFFFF) across tables/constants/descriptors, wrapping DXBC chunk offsets and chunk payload sizes, and rich V1.2 canonical round-trips.Benchmark (
clang++ -std=c++20 -O2, bit-exact A/B, 200,000 encodes of a 12-table / 48-range / 8-sampler V1.2 signature, 2,008 bytes)main):538.91 ms18.26 ms(29.52x faster, byte-identical output verified)Verification
runtime/test/root_signature_test.cppcleanly under:clang++ -std=c++20 -O1 -g -fsanitize=address,undefined -Wall -Wextra -Werrorclang++ -std=c++20 -O1 -g -fsanitize=thread -Wall -Wextra -Werrorclang++ -std=c++20 -O2 -Wall -Wextra -Werrorpython3 -I scripts/check_no_game_data.py runtime/src/root_signature.cpp runtime/test/root_signature_test.cppandpython3 -I tests/test_text_write_line_endings.py: all passed.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.