HLE: encode async results without reading struct padding #2625

Open
github-bot wants to merge 1 commit from github-bot/gh-2625 into main AGit
Owner

@⁠XeNS1 on GitHub · 2026-11-25 17:03 UTC · original
XeNS1:codex/async-result-byte-encoding-20261125 → main · +212 −9 · 2 files · 1 commits · open

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.

**@⁠XeNS1** on GitHub · 2026-11-25 17:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2625) `XeNS1:codex/async-result-byte-encoding-20261125` → `main` · +212 −9 · 2 files · 1 commits · open `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://git.gtahub.st/github/Marvisak--VIctory/issues/1633). #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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:10:36 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 17:38 UTC · original

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.

**@⁠oni-swr** on GitHub · 2026-11-25 17:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2625#issuecomment-7169783177) 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.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 17:45 UTC · original

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.

**@⁠kotekompotek** on GitHub · 2026-11-25 17:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/2625#issuecomment-7169948063) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 22:20 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 22:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2625#issuecomment-7176233128) <!-- 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)_
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 05:10 UTC · original · approved these changes

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).

**@⁠Dukestar69** on GitHub · 2026-11-26 05:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2625#pullrequestreview-6068855924) · **approved these changes** 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).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 16:05 UTC · original · approved these changes

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].
**@⁠fuzeofficlal** on GitHub · 2026-11-26 16:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/2625#pullrequestreview-6077245080) · **approved these changes** 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2625/head:github-bot/gh-2625'
git switch 'github-bot/gh-2625'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2625'
git switch 'github-bot/gh-2625'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2625'
git switch 'github-bot/gh-2625'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2625'
git switch 'main'
git merge --squash 'github-bot/gh-2625'
git switch 'main'
git merge --ff-only 'github-bot/gh-2625'
git switch 'main'
git merge 'github-bot/gh-2625'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2625
No description provided.