HLE rpcrt4: fix GUID brace parsing and UuidToString OOM handling #3376

Open
Arkenoz wants to merge 2 commits from upstream-pr/3376 into main
Arkenoz commented 2026-11-26 20:55:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Arkenoz on 2026-11-26T20:55:18Z.


Tracked in #1633.

Problem

  1. parse() in crates/victory-hle/src/modules/rpcrt4.rs accepted trailing characters after a closing } (returning immediately without checking that the iterator was exhausted), unmatched braces ({... or ...}), and repeated opening braces ({{...}).
  2. UuidToStringA and UuidToStringW ignored allocation failure from allocate(), writing a null pointer to out and returning OK instead of OUT_OF_MEMORY.

Changes

  • Tracked whether an opening { was seen in parse(), rejecting repeated {, unmatched braces, and any trailing characters after }.
  • Checked allocate(&bytes) for null in UuidToStringA and UuidToStringW, returning OUT_OF_MEMORY without writing to out.
  • Added unit test cases in garbage_is_refused for trailing characters after }, unmatched braces, and duplicate opening braces.

Verification

  • cargo test -p victory-hle rpcrt4 (5 passed)
  • cargo clippy -p victory-hle --all-targets (0 warnings)

AI-assisted with Gemini.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5517021079 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3376). Originally posted by [Arkenoz](https://github.com/Arkenoz) on 2026-11-26T20:55:18Z. --- Tracked in #1633. ### Problem 1. `parse()` in `crates/victory-hle/src/modules/rpcrt4.rs` accepted trailing characters after a closing `}` (returning immediately without checking that the iterator was exhausted), unmatched braces (`{...` or `...}`), and repeated opening braces (`{{...}`). 2. `UuidToStringA` and `UuidToStringW` ignored allocation failure from `allocate()`, writing a null pointer to `out` and returning `OK` instead of `OUT_OF_MEMORY`. ### Changes - Tracked whether an opening `{` was seen in `parse()`, rejecting repeated `{`, unmatched braces, and any trailing characters after `}`. - Checked `allocate(&bytes)` for null in `UuidToStringA` and `UuidToStringW`, returning `OUT_OF_MEMORY` without writing to `out`. - Added unit test cases in `garbage_is_refused` for trailing characters after `}`, unmatched braces, and duplicate opening braces. ### Verification - `cargo test -p victory-hle rpcrt4` (5 passed) - `cargo clippy -p victory-hle --all-targets` (0 warnings) AI-assisted with Gemini.
Dukestar69 commented 2026-11-26 21:09:32 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T21:09:32Z.

Review: APPROVED


LGTM — verified on Windows against origin/main (63bcca4).

  • Returning OUT_OF_MEMORY on null allocation in UuidToStringA/UuidToStringW and rejecting mismatched/duplicate braces or trailing garbage in parse cleanly hardens rpcrt4.
  • cargo test -p victory-hle --lib modules::rpcrt4:: -- --test-threads=1: 5 passed, 0 failed.
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6080503039 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3376#pullrequestreview-6080503039). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T21:09:32Z. **Review:** APPROVED --- LGTM — verified on Windows against `origin/main` (`63bcca4`). - Returning `OUT_OF_MEMORY` on null allocation in `UuidToStringA`/`UuidToStringW` and rejecting mismatched/duplicate braces or trailing garbage in `parse` cleanly hardens `rpcrt4`. - `cargo test -p victory-hle --lib modules::rpcrt4:: -- --test-threads=1`: 5 passed, 0 failed. - `cargo clippy -p victory-hle --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
passerbyyhx commented 2026-11-26 21:31:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-26T21:31:36Z.


I ran the Windows differential test from #1975 against both PR heads. With 64-bit System32 rpcrt4.dll 10.0.26100.9949, it passes on 72a7ec1f (#1975) and fails on 99bd788d (this PR) at the null input. A separate non-short-circuiting matrix checks both the status and the complete 16-byte destination, initialized to a sentinel. ANSI and UTF-16 agreed in every row.

Input Native Windows and #1975 This PR
Null text pointer, valid output 0, writes nil UUID 1705, leaves sentinel
Canonical UUID 0, writes parsed UUID Same
Canonical UUID in matched braces 1705, leaves sentinel 0, writes parsed UUID
Matched braces followed by a character 1705, leaves sentinel Same
Valid hex digits with all hyphens removed 1705, leaves sentinel 0, writes parsed UUID
Empty string 1705, leaves sentinel Same

That is 12/12 matching native rows for #1975 and 6/12 for this head. For parsing parity I would keep #1975's exact grammar and null-input behavior when reconciling the patches. This exercise did not inject allocation failure into UuidToString. Each PR was built in a separate Cargo target directory. Synthetic inputs only.

AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7203810218 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3376#issuecomment-7203810218). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-26T21:31:36Z. --- I ran the Windows differential test from #1975 against both PR heads. With 64-bit System32 rpcrt4.dll 10.0.26100.9949, it passes on `72a7ec1f` (#1975) and fails on `99bd788d` (this PR) at the null input. A separate non-short-circuiting matrix checks both the status and the complete 16-byte destination, initialized to a sentinel. ANSI and UTF-16 agreed in every row. | Input | Native Windows and #1975 | This PR | |---|---|---| | Null text pointer, valid output | 0, writes nil UUID | 1705, leaves sentinel | | Canonical UUID | 0, writes parsed UUID | Same | | Canonical UUID in matched braces | 1705, leaves sentinel | 0, writes parsed UUID | | Matched braces followed by a character | 1705, leaves sentinel | Same | | Valid hex digits with all hyphens removed | 1705, leaves sentinel | 0, writes parsed UUID | | Empty string | 1705, leaves sentinel | Same | That is 12/12 matching native rows for #1975 and 6/12 for this head. For parsing parity I would keep #1975's exact grammar and null-input behavior when reconciling the patches. This exercise did not inject allocation failure into UuidToString. Each PR was built in a separate Cargo target directory. Synthetic inputs only. AI-assisted with Codex.
Arkenoz commented 2026-11-27 00:16:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Arkenoz on 2026-11-27T00:16:08Z.


Thanks for running the native Windows comparison! Updated UuidFromStringA, UuidFromStringW, and parse() to match native rpcrt4.dll behavior across all 12 cases:

  • Null string pointer with valid uuid now writes the nil UUID and returns OK.
  • parse() now enforces strict canonical 36-char 8-4-4-4-12 hex grammar (rejecting braces, hyphenless/misplaced-hyphen strings, trailing characters, and empty strings) while leaving uuid untouched on INVALID_STRING_UUID.
  • Kept the OUT_OF_MEMORY checks in UuidToStringA / UuidToStringW.
  • Added unit tests covering all 6 native cases for both UuidFromStringA and UuidFromStringW (cargo test -p victory-hle rpcrt4 — 7 passed, clippy -D warnings clean).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7206318595 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3376#issuecomment-7206318595). Originally posted by [Arkenoz](https://github.com/Arkenoz) on 2026-11-27T00:16:08Z. --- Thanks for running the native Windows comparison! Updated `UuidFromStringA`, `UuidFromStringW`, and `parse()` to match native `rpcrt4.dll` behavior across all 12 cases: - Null string pointer with valid `uuid` now writes the nil UUID and returns `OK`. - `parse()` now enforces strict canonical 36-char `8-4-4-4-12` hex grammar (rejecting braces, hyphenless/misplaced-hyphen strings, trailing characters, and empty strings) while leaving `uuid` untouched on `INVALID_STRING_UUID`. - Kept the `OUT_OF_MEMORY` checks in `UuidToStringA` / `UuidToStringW`. - Added unit tests covering all 6 native cases for both `UuidFromStringA` and `UuidFromStringW` (`cargo test -p victory-hle rpcrt4` — 7 passed, `clippy -D warnings` clean).
fuzeofficlal commented 2026-11-27 01:11:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:11:06Z.

Review: APPROVED


Looks good. Verified UuidFromStringA/W directly against native Windows 11 rpcrt4.dll across 12 test vectors (null pointer returning RPC_S_OK with nil UUID, empty string, lowercase/uppercase canonical UUIDs, braced UUIDs, braced + trailing text, missing/misplaced hyphens, leading/trailing whitespace, unmatched braces) with 0 mismatches on both return codes and output Guid preservation. The UuidToStringA/W null-allocation check returning RPC_S_OUT_OF_MEMORY before writing *out is also clean.

Verified:

  • cargo xtask policy passes cleanly.
  • cargo clippy --tests -p victory-hle (default and --features diagnostics, -D warnings) passes with zero warnings.
  • cargo test --locked -p victory-hle --lib modules::rpcrt4:: passes (7/7).
<!-- greyfinch-sync:Marvisak/VIctory:review:6082188456 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3376#pullrequestreview-6082188456). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T01:11:06Z. **Review:** APPROVED --- Looks good. Verified `UuidFromStringA`/`W` directly against native Windows 11 `rpcrt4.dll` across 12 test vectors (null pointer returning `RPC_S_OK` with nil UUID, empty string, lowercase/uppercase canonical UUIDs, braced UUIDs, braced + trailing text, missing/misplaced hyphens, leading/trailing whitespace, unmatched braces) with 0 mismatches on both return codes and output `Guid` preservation. The `UuidToStringA`/`W` null-allocation check returning `RPC_S_OUT_OF_MEMORY` before writing `*out` is also clean. Verified: - `cargo xtask policy` passes cleanly. - `cargo clippy --tests -p victory-hle` (default and `--features diagnostics`, `-D warnings`) passes with zero warnings. - `cargo test --locked -p victory-hle --lib modules::rpcrt4::` passes (7/7).
passerbyyhx commented 2026-11-29 16:22:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by passerbyyhx on 2026-11-29T16:22:20Z.


Re-ran the same native Windows differential on 1f1a3d6f7fc857d0f0c6cfe252c81f62add9e5d4. All 12/12 rows now match System32 rpcrt4.dll for both return code and the full 16-byte destination, up from 6/12 on 99bd788d359505d738770777e503bab89931b3aa. The matrix covers UuidFromStringA and UuidFromStringW, each with null input, canonical text, braces, braces with trailing text, omitted hyphens, and an empty string. Outputs start as a nonzero sentinel in every case.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7258850852 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3376#issuecomment-7258850852). Originally posted by [passerbyyhx](https://github.com/passerbyyhx) on 2026-11-29T16:22:20Z. --- Re-ran the same native Windows differential on `1f1a3d6f7fc857d0f0c6cfe252c81f62add9e5d4`. All **12/12** rows now match System32 `rpcrt4.dll` for both return code and the full 16-byte destination, up from **6/12** on `99bd788d359505d738770777e503bab89931b3aa`. The matrix covers `UuidFromStringA` and `UuidFromStringW`, each with null input, canonical text, braces, braces with trailing text, omitted hyphens, and an empty string. Outputs start as a nonzero sentinel in every case.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3376:upstream-pr/3376'
git switch 'upstream-pr/3376'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3376'
git switch 'upstream-pr/3376'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3376'
git switch 'upstream-pr/3376'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3376'
git switch 'main'
git merge --squash 'upstream-pr/3376'
git switch 'main'
git merge --ff-only 'upstream-pr/3376'
git switch 'main'
git merge 'upstream-pr/3376'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
Marvisak/VIctory!3376
No description provided.