HLE: encode async results without reading struct padding #2623

Open
XeNS1 wants to merge 1 commit from upstream-pr/2625 into main
XeNS1 commented 2026-11-25 17:03:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by XeNS1 on 2026-11-25T17:03:15Z.


xasync::bytes<T: Copy> treats the entire Rust representation of T as initialized u8s. Copy does not guarantee initialized padding. GameLicense is a concrete padded caller: its 104-byte x64 result includes gaps at bytes 22–23 and 92–95, which the old helper can read while copying the result into a vector.

Require an explicit ResultBytes encoding. The existing scalar and handle types encode their native-ABI values directly; GameLicense writes each field at its repr(C) offset into the final zero-initialized byte buffer. This removes the generic raw-memory read and keeps existing call sites, result sizes and licensing behavior. A future record needs its own encoder.

Claim: serialize async result fields without reading struct padding. #1194 adds XStore tests and an installed-package helper in the same file; its work is separate.

Validation on Linux x86-64, Rust 1.100.0:

  • The unmodified base fails to build victory-hle because victory-gpu/src/resource.rs references Windows-only IDLE_FRAMES, IDLE_MS, and host_resource on Linux. No GPU changes are included here.
  • An isolated Cargo harness imports the actual complete xasync.rs, xstore.rs, xpackage.rs, and runtime.rs files by path, together with verbatim shared ABI types/helpers from xgameruntime.rs (excluding its unrelated area registry). 22 module tests and 1 compile-fail doc test pass, with two build workers and one test thread. This is partial local validation; full Windows integration is verified by CI below.
  • New ABI coverage sends scalar boundaries, null/live const/mut handles, and every non-default GameLicense field through async result retrieval. It also checks the 104-byte layout and zero padding.
  • The new compile-fail doc test fails with the original helper because a padded record without an encoder still compiles; it passes with the new bound. The native layout tests also pass on the original build; Miri was not run.
  • Harness Clippy (all targets, warnings denied, undocumented unsafe blocks checked), rustfmt for both changed files, git diff --check, and asset policy (184 repository files / 2 staged files) pass.

Windows CI passed on head 454c69c: workspace Clippy, workspace Clippy with all features, and the full workspace test suite, using the repository-pinned Rust 1.98.1 toolchain.

All fixtures are synthetic values and strings. No game files were accessed, committed or executed. No dependencies added.

References: Rust's MaybeUninit initialization/padding rules, Microsoft's XStoreGameLicense layout.

AI-assisted implementation and validation: OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6609563660 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2625). Originally posted by [XeNS1](https://github.com/XeNS1) on 2026-11-25T17:03:15Z. --- `xasync::bytes<T: Copy>` treats the entire Rust representation of `T` as initialized `u8`s. `Copy` does not guarantee initialized padding. `GameLicense` is a concrete padded caller: its 104-byte x64 result includes gaps at bytes 22–23 and 92–95, which the old helper can read while copying the result into a vector. Require an explicit `ResultBytes` encoding. The existing scalar and handle types encode their native-ABI values directly; `GameLicense` writes each field at its `repr(C)` offset into the final zero-initialized byte buffer. This removes the generic raw-memory read and keeps existing call sites, result sizes and licensing behavior. A future record needs its own encoder. Claim: [serialize async result fields without reading struct padding](https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7168715592). #1194 adds XStore tests and an installed-package helper in the same file; its work is separate. Validation on Linux x86-64, Rust 1.100.0: - The unmodified base fails to build `victory-hle` because `victory-gpu/src/resource.rs` references Windows-only `IDLE_FRAMES`, `IDLE_MS`, and `host_resource` on Linux. No GPU changes are included here. - An isolated Cargo harness imports the **actual complete** `xasync.rs`, `xstore.rs`, `xpackage.rs`, and `runtime.rs` files by path, together with verbatim shared ABI types/helpers from `xgameruntime.rs` (excluding its unrelated area registry). **22 module tests and 1 compile-fail doc test pass**, with two build workers and one test thread. This is partial local validation; full Windows integration is verified by CI below. - New ABI coverage sends scalar boundaries, null/live const/mut handles, and every non-default `GameLicense` field through async result retrieval. It also checks the 104-byte layout and zero padding. - The new compile-fail doc test fails with the original helper because a padded record without an encoder still compiles; it passes with the new bound. The native layout tests also pass on the original build; Miri was not run. - Harness Clippy (all targets, warnings denied, undocumented unsafe blocks checked), rustfmt for both changed files, `git diff --check`, and asset policy (184 repository files / 2 staged files) pass. [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/45660585217) passed on head `454c69c`: workspace Clippy, workspace Clippy with all features, and the full workspace test suite, using the repository-pinned Rust 1.98.1 toolchain. All fixtures are synthetic values and strings. No game files were accessed, committed or executed. No dependencies added. References: Rust's [MaybeUninit initialization/padding rules](https://doc.rust-lang.org/std/mem/union.MaybeUninit.html), Microsoft's [XStoreGameLicense layout](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xstore/structs/xstoregamelicense). AI-assisted implementation and validation: OpenAI Codex.
oni-swr commented 2026-11-25 18:02:47 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T17:38:06Z.


Independent verification (no physical GPU, no game files, no competing PR). AI-assisted: Claude Code (Claude Sonnet 5.5).

  • Environment: Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1, VICTORY_D3D12_WARP=1 and VICTORY_WARP=1 set (no GPU is touched by these host-side tests).
  • origin/main = 13f91caee2
  • PR head: 454c69c946 (based on the main tip; merges cleanly)

Results

  • cargo test -p victory-hle --locked --lib result_bytes: 2 passed (result_bytes_round_trip_scalars_and_handles, game_license_result_bytes_follow_the_abi_and_zero_padding).
  • cargo test -p victory-hle --locked --lib: 148 passed, 0 failed, 0 ignored.
  • cargo test -p victory-hle --locked --doc: 1 passed (the compile_fail doctest showing a padded record is rejected by xasync::bytes).
  • cargo clippy -p victory-hle --all-targets --locked: no warnings.
  • Negative control: not applicable; the new tests use the new ResultBytes API and do not compile on origin/main.

Review: every existing xasync::bytes caller (xgamesave, xnetworking, xpackage, xstore) still compiles with the ResultBytes bound. GameLicense is encoded field by field at offset_of! positions into a zeroed 104-byte buffer, so the 6 bytes after is_trial and the 4 before expiration are always zero and no padding is read. The diff also contains rustfmt-style re-wraps of unrelated lines in xasync.rs (harmless, but it enlarges the diff). No correctness issues found.

Not tested: any real title, or how the Windows runtime consumes the result (these are host-side HLE unit tests only). No GPU involved.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169783177 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2625#issuecomment-7169783177). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T17:38:06Z. --- Independent verification (no physical GPU, no game files, no competing PR). AI-assisted: Claude Code (Claude Sonnet 5.5). - Environment: Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1, `VICTORY_D3D12_WARP=1` and `VICTORY_WARP=1` set (no GPU is touched by these host-side tests). - `origin/main` = 13f91caee25f2fdf2c062be5f7a27f058e51cbca - PR head: 454c69c9467e6972856d8d4ee868235a1ceeca23 (based on the main tip; merges cleanly) **Results** - `cargo test -p victory-hle --locked --lib result_bytes`: 2 passed (`result_bytes_round_trip_scalars_and_handles`, `game_license_result_bytes_follow_the_abi_and_zero_padding`). - `cargo test -p victory-hle --locked --lib`: 148 passed, 0 failed, 0 ignored. - `cargo test -p victory-hle --locked --doc`: 1 passed (the `compile_fail` doctest showing a padded record is rejected by `xasync::bytes`). - `cargo clippy -p victory-hle --all-targets --locked`: no warnings. - Negative control: not applicable; the new tests use the new `ResultBytes` API and do not compile on `origin/main`. **Review**: every existing `xasync::bytes` caller (`xgamesave`, `xnetworking`, `xpackage`, `xstore`) still compiles with the `ResultBytes` bound. `GameLicense` is encoded field by field at `offset_of!` positions into a zeroed 104-byte buffer, so the 6 bytes after `is_trial` and the 4 before `expiration` are always zero and no padding is read. The diff also contains rustfmt-style re-wraps of unrelated lines in `xasync.rs` (harmless, but it enlarges the diff). No correctness issues found. **Not tested**: any real title, or how the Windows runtime consumes the result (these are host-side HLE unit tests only). No GPU involved.
kotekompotek commented 2026-11-25 18:02:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T17:45:08Z.


Reviewed: replacing the raw size_of::<T> copy in bytes() with the ResultBytes trait closes the uninit-padding read — the compile_fail doctest proves padded records can no longer use the generic path, and GameLicense encodes fields explicitly. Scalar/pointer round-trip tests cover the ABI. CI green.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7169948063 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2625#issuecomment-7169948063). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T17:45:08Z. --- Reviewed: replacing the raw `size_of::<T>` copy in `bytes()` with the `ResultBytes` trait closes the uninit-padding read — the compile_fail doctest proves padded records can no longer use the generic path, and `GameLicense` encodes fields explicitly. Scalar/pointer round-trip tests cover the ABI. CI green.
Marvisak commented 2026-11-25 23:06:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T22:20:06Z.


Automated triage for the maintainers.

Recommended for a maintainer's look. xasync::bytes on main copies a Copy value's whole memory as u8s, which reads uninitialized padding (undefined behaviour in Rust) for padded records; xstore::GameLicense is one (18 bytes + 4 bools, then a u32, 64 bytes, then an i64: gaps at 22–23 and 92–95). The PR replaces the generic read with a ResultBytes trait: scalars and handles encode their native bytes, and GameLicense writes each field at its offset_of! into a zeroed buffer, so sizes and the bytes the title receives are unchanged except that padding is now zero. I checked the existing callers (xgamesave passes an i64 and a handle) still fit the new bound. Minor: the diff also re-wraps a few unrelated lines in pending_with (rustfmt churn), which could be dropped. Merges cleanly, CI check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7176233128 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2625#issuecomment-7176233128). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T22:20:06Z. --- <!-- victory-triage v1 head=454c69c9467e6972856d8d4ee868235a1ceeca23 verdict=merge-candidate at=2026-11-25T22:30:30Z --> Automated triage for the maintainers. Recommended for a maintainer's look. `xasync::bytes` on `main` copies a `Copy` value's whole memory as `u8`s, which reads uninitialized padding (undefined behaviour in Rust) for padded records; `xstore::GameLicense` is one (18 bytes + 4 bools, then a `u32`, 64 bytes, then an `i64`: gaps at 22–23 and 92–95). The PR replaces the generic read with a `ResultBytes` trait: scalars and handles encode their native bytes, and `GameLicense` writes each field at its `offset_of!` into a zeroed buffer, so sizes and the bytes the title receives are unchanged except that padding is now zero. I checked the existing callers (`xgamesave` passes an `i64` and a handle) still fit the new bound. Minor: the diff also re-wraps a few unrelated lines in `pending_with` (rustfmt churn), which could be dropped. Merges cleanly, CI `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Dukestar69 commented 2026-11-26 05:10:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T05:10:29Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64:

  • cargo test -p victory-hle --lib modules::xasync::: 14 passed, 0 failed (including new result_bytes_round_trip_scalars_and_handles).
  • cargo test -p victory-hle --lib modules::xstore::: 4 passed, 0 failed (including new game_license_result_bytes_follow_the_abi_and_zero_padding).
  • 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:6068855924 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2625#pullrequestreview-6068855924). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T05:10:29Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64: - `cargo test -p victory-hle --lib modules::xasync::`: **14 passed, 0 failed** (including new `result_bytes_round_trip_scalars_and_handles`). - `cargo test -p victory-hle --lib modules::xstore::`: **4 passed, 0 failed** (including new `game_license_result_bytes_follow_the_abi_and_zero_padding`). - `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).
fuzeofficlal commented 2026-11-26 16:05:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T16:05:30Z.

Review: APPROVED


Reviewed 454c69c9467e6972856d8d4ee868235a1ceeca23 (merged cleanly onto 63bcca43c6a00a758510398fa43096ce7e4f7df0) and verified on Windows 11 x64 (rustc 1.98.1 MSVC).

Audit

  • crates/victory-hle/src/modules/xasync.rs:918, :955: replacing the generic Copy raw-memory copy in bytes() with the explicit ResultBytes trait removes undefined behavior from reading uninitialized struct padding, and the compile_fail doctest ensures future padded records cannot bypass explicit encoding. All 7 existing callers across xgamesave, xnetworking, xpackage, and xstore fit cleanly.
  • crates/victory-hle/src/modules/xstore.rs:167, :178: GameLicense::into_result_bytes writes all 8 fields via std::mem::offset_of! into a zero-initialized 104-byte buffer, matching the #[repr(C)] layout (align == 8, fields at offsets 0, 18, 19, 20, 21, 24, 28, 96) and deterministically zeroing both padding gaps (22..24 and 92..96).
  • Minor non-blocking note: xasync.rs includes a few unrelated rustfmt line wraps in pending_with and an existing test.

Verification

  • Clean merge onto 63bcca43c6a00a758510398fa43096ce7e4f7df0 + cargo run -p xtask -- policy (191 files ok)
  • cargo clippy -p victory-hle --all-targets -- -D warnings (default & --all-features)
  • cargo test -p victory-hle --lib -- modules::xasync:: modules::xstore:: modules::xgamesave:: modules::xnetworking:: modules::xpackage::: 32/32 passed
  • cargo test -p victory-hle --doc: 1/1 passed (compile_fail doctest)
  • Additional probe verified all 8 offset_of! values (size == 104, align == 8) and pre-poisoned a MaybeUninit<GameLicense> storage slot with 0xFF before writing only the fields: xasync::bytes still emitted exact zero bytes at [22..24] and [92..96].
<!-- greyfinch-sync:Marvisak/VIctory:review:6077245080 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2625#pullrequestreview-6077245080). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T16:05:30Z. **Review:** APPROVED --- Reviewed `454c69c9467e6972856d8d4ee868235a1ceeca23` (merged cleanly onto `63bcca43c6a00a758510398fa43096ce7e4f7df0`) and verified on Windows 11 x64 (`rustc 1.98.1` MSVC). ### Audit - `crates/victory-hle/src/modules/xasync.rs:918`, `:955`: replacing the generic `Copy` raw-memory copy in `bytes()` with the explicit `ResultBytes` trait removes undefined behavior from reading uninitialized struct padding, and the `compile_fail` doctest ensures future padded records cannot bypass explicit encoding. All 7 existing callers across `xgamesave`, `xnetworking`, `xpackage`, and `xstore` fit cleanly. - `crates/victory-hle/src/modules/xstore.rs:167`, `:178`: `GameLicense::into_result_bytes` writes all 8 fields via `std::mem::offset_of!` into a zero-initialized 104-byte buffer, matching the `#[repr(C)]` layout (`align == 8`, fields at offsets `0, 18, 19, 20, 21, 24, 28, 96`) and deterministically zeroing both padding gaps (`22..24` and `92..96`). - Minor non-blocking note: `xasync.rs` includes a few unrelated rustfmt line wraps in `pending_with` and an existing test. ### Verification - Clean merge onto `63bcca43c6a00a758510398fa43096ce7e4f7df0` + `cargo run -p xtask -- policy` (`191 files ok`) - `cargo clippy -p victory-hle --all-targets -- -D warnings` (default & `--all-features`) - `cargo test -p victory-hle --lib -- modules::xasync:: modules::xstore:: modules::xgamesave:: modules::xnetworking:: modules::xpackage::`: **32/32 passed** - `cargo test -p victory-hle --doc`: **1/1 passed** (`compile_fail` doctest) - Additional probe verified all 8 `offset_of!` values (`size == 104`, `align == 8`) and pre-poisoned a `MaybeUninit<GameLicense>` storage slot with `0xFF` before writing only the fields: `xasync::bytes` still emitted exact zero bytes at `[22..24]` and `[92..96]`.
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/2625:upstream-pr/2625'
git switch 'upstream-pr/2625'

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/2625'
git switch 'upstream-pr/2625'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2625'
git switch 'upstream-pr/2625'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2625'
git switch 'main'
git merge --squash 'upstream-pr/2625'
git switch 'main'
git merge --ff-only 'upstream-pr/2625'
git switch 'main'
git merge 'upstream-pr/2625'
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!2623
No description provided.