Repository navigation
d3d12/hle: fix GUID parsing, OOM reporting and unaligned access in rpcrt4 - #2579
Conversation
…llocation says so (D3D12-HLE-RPCRT4-UUID-PARSE-AND-OOM-BOUNDS)
|
Note on the CI: this pull request changes one Rust file under |
lixonik
left a comment
There was a problem hiding this comment.
Reviewed d6e73e167 (d3d12/crates/leonida-hle/src/modules/rpcrt4.rs).
The read_unaligned/write_unaligned helpers handle arbitrary guest GUID alignment, the canonical ASCII parser (36 chars or {36} with - at 8/13/18/23) rejects malformed or non-ASCII inputs without clobbering *out, and publish reports RPC_S_OUT_OF_MEMORY cleanly 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).
|
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). |
|
Verified by OreoFR
AI-assisted (Claude Code, Claude Opus 5.5). |
Claimed in the coordination issue as:
D3D12-HLE-RPCRT4-UUID-PARSE-AND-OOM-BOUNDS(#2570 (comment))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.)