d3d12/hle: fix GUID parsing, OOM reporting and unaligned access in rpcrt4 #2579
No reviewers
Labels
No labels
accessibility
area: ci
area: d3d12
area: docs
area: launcher
area: runtime (legacy)
area: shader translator
area: tools
area: viewer
bug
dependencies
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs in-game run
needs rebase
needs-triage
question
ready-for-agent
submodules
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!2579
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2579"
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?
@Mby159 on GitHub · 2026-11-28 16:03 UTC · original
Mby159:fix/d3d12-hle-rpcrt4-uuid-parse-and-oom-bounds→main· +179 −27 · 1 files · 1 commits · merged 2026-11-28 20:19 UTCClaimed in the coordination issue as:
D3D12-HLE-RPCRT4-UUID-PARSE-AND-OOM-BOUNDS(#2570)What and why
Three defects in
d3d12/crates/leonida-hle/src/modules/rpcrt4.rs, all in the GUID calls a title loads the RPC runtime for.1.
parse()took any text whose first 32 non-dash characters were hex digits. Win32rpcrt4refuses all of these withRPC_S_INVALID_STRING_UUID(1705):{with no matching},}with no opening{,}(the old parser returned as soon as it had seen the 33rd character, so{...}trailingparsed as a GUID),-at any position, or none at all.The parser now takes the canonical form only: 32 hex digits with the dashes at 8, 13, 18 and 23, and the braces both there or both not (36 or 38 characters, ASCII only). Everything else is
RPC_S_INVALID_STRING_UUID, and a refused text leaves the caller'sGuiduntouched.2.
UuidToStringA/UuidToStringWreported success on a failed allocation. They returnedRPC_S_OK(0) with*out == nullwhen the allocation failed, so a title could not tell an empty string from an out-of-memory one. Both now reportRPC_S_OUT_OF_MEMORY(14) and leave the caller's pointer as it was (publish()).3. The caller's
Guidwas read and written with aligned accesses.UuidCreate,UuidFromStringA/WandUuidToStringA/Wusedwrite()/as_ref(), which require the caller's pointer to be aligned forGuid(4 bytes). AGuidin a title's own buffer need not be, and an aligned access to a misaligned address is undefined behaviour (it faults in a debug build). These are nowwrite_unaligned/read_unaligned.Tested
cargo test --package leonida-hle --locked:186 passed; 0 failed; 2 ignored(10 inmodules::rpcrt4, 5 of them new).}, a misplaced dash, a missing dash, empty text, text longer than any legal form), the canonical form with braces and in upper case, a wide string with a non-ASCII unit, a refused text leaving theGuidas it was,publish()reportingRPC_S_OUT_OF_MEMORYwithout touching the caller's pointer, and aGuidat an odd address (an 8-byte aligned buffer plus 1) written and read back - the aligned access this replaces panics in a debug build.cargo clippy --package leonida-hle --all-targets --no-deps --locked -- -D warnings: no new findings. With the pre-change version ofrpcrt4.rsput back in place the command's output is byte-identical to the branch's - 28 lint locations in both, inleonida-gpu,leonida-shader, andleonida-hle'sxmem.rs/dstorage.rs/clock.rs/gameinput.rs- and none of them is in the file this pull request touches. The command exits non-zero onmainas well, because-D warningsturns those pre-existing findings into errors.rustfmt --edition 2024 --check crates/leonida-hle/src/modules/rpcrt4.rs: clean.python -I scripts/check_no_game_data.py d3d12/crates/leonida-hle/src/modules/rpcrt4.rs(exit 0).GPUs tested: n/a (a CPU-only HLE module; verified on Windows 11 x64)
AI-assisted: yes
Checklist
maind48a957bband merges cleanly into the currentmain: no commit since that base touchesd3d12/crates/leonida-hle, so the one file this pull request changes is untouched upstream (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: this pull request adds no translator rule.)@Mby159 on GitHub · 2026-11-28 16:08 UTC · original
Note on the CI: this pull request changes one Rust file under
d3d12/, and the repository's jobs do not build or run thed3d12/Rust crates at all (the nestedd3d12/.github/workflows/ci.ymlis not executed; the root workflow only buildstools/bcpack_calibration). Thestdlib-tests-linux,macos-pythonandsemantic-testsfailures are the red tests thatmaincarries on its own — the same set of jobs fails on the other open pull requests (#2575, #2566, #2549 and #2548 all show it). The change itself is verified in the description:cargo test --package leonida-hle --locked(186 passed, 0 failed), clippy with no new findings,rustfmt --check, andpython -I scripts/check_no_game_data.py.@lixonik on GitHub · 2026-11-28 20:07 UTC · original · approved these changes
Reviewed
d6e73e167(d3d12/crates/leonida-hle/src/modules/rpcrt4.rs).The
read_unaligned/write_unalignedhelpers handle arbitrary guestGUIDalignment, the canonical ASCII parser (36chars or{36}with-at8/13/18/23) rejects malformed or non-ASCII inputs without clobbering*out, andpublishreportsRPC_S_OUT_OF_MEMORYcleanly when allocation fails.Local verification:
cargo test --manifest-path d3d12/Cargo.toml -p leonida-hle --lib rpcrt4: 10/10 passed (a_created_guid_is_version_four,a_guid_formats_and_parses_back,a_malformed_guid_is_refused,a_text_outside_ascii_is_refused,a_refused_text_leaves_the_guid_alone,garbage_is_refused,a_failed_allocation_leaves_the_callers_pointer_alone,a_misaligned_guid_is_written_and_read,uuid_from_string_writes_what_it_reads,a_string_is_freed_once_through_either_call).python -I scripts/check_no_game_data.py: passed.AI-assisted (Antigravity, Gemini).
@MoonEyes on GitHub · 2026-11-28 20:19 UTC · original
Red/green: On main the rpcrt4 tests a_malformed_guid_is_refused and a_refused_text_leaves_the_guid_alone fail (a GUID without its closing brace or with misplaced dashes is accepted), and with the PR cargo test -p leonida-hle --lib -- rpcrt4 passes (12 OK) on Windows 11 at OreoFR's (RTX 4070).
Independent tester (OreoFR, RTX 4070, Windows 11): PR head merged with the other PRs of its batch on main
c1ecf04ed, full ctest run (485 tests, tests that launch the game excluded): no new failure compared with main.@OreoFR on GitHub · 2026-11-28 22:05 UTC · original
Verified by OreoFR
54d27d988+ PR headd6e73e167; green run in a merge package of 5 PRs, no new ctest failure vs maincargo test -p leonida-hle --lib --locked -- rpcrt4AI-assisted (Claude Code, Claude Opus 5.5).