HLE: encode async results without reading struct padding #2625
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2625
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2625"
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?
@XeNS1 on GitHub · 2026-11-25 17:03 UTC · original
XeNS1:codex/async-result-byte-encoding-20261125→main· +212 −9 · 2 files · 1 commits · openxasync::bytes<T: Copy>treats the entire Rust representation ofTas initializedu8s.Copydoes not guarantee initialized padding.GameLicenseis 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
ResultBytesencoding. The existing scalar and handle types encode their native-ABI values directly;GameLicensewrites each field at itsrepr(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:
victory-hlebecausevictory-gpu/src/resource.rsreferences Windows-onlyIDLE_FRAMES,IDLE_MS, andhost_resourceon Linux. No GPU changes are included here.xasync.rs,xstore.rs,xpackage.rs, andruntime.rsfiles by path, together with verbatim shared ABI types/helpers fromxgameruntime.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.GameLicensefield through async result retrieval. It also checks the 104-byte layout and zero padding.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.
@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).
VICTORY_D3D12_WARP=1andVICTORY_WARP=1set (no GPU is touched by these host-side tests).origin/main=13f91caee2454c69c946(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 (thecompile_faildoctest showing a padded record is rejected byxasync::bytes).cargo clippy -p victory-hle --all-targets --locked: no warnings.ResultBytesAPI and do not compile onorigin/main.Review: every existing
xasync::bytescaller (xgamesave,xnetworking,xpackage,xstore) still compiles with theResultBytesbound.GameLicenseis encoded field by field atoffset_of!positions into a zeroed 104-byte buffer, so the 6 bytes afteris_trialand the 4 beforeexpirationare always zero and no padding is read. The diff also contains rustfmt-style re-wraps of unrelated lines inxasync.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 on GitHub · 2026-11-25 17:45 UTC · original
Reviewed: replacing the raw
size_of::<T>copy inbytes()with theResultBytestrait closes the uninit-padding read — the compile_fail doctest proves padded records can no longer use the generic path, andGameLicenseencodes fields explicitly. Scalar/pointer round-trip tests cover the ABI. CI green.@Marvisak on GitHub · 2026-11-25 22:20 UTC · original
Automated triage for the maintainers.
Recommended for a maintainer's look.
xasync::bytesonmaincopies aCopyvalue's whole memory asu8s, which reads uninitialized padding (undefined behaviour in Rust) for padded records;xstore::GameLicenseis one (18 bytes + 4 bools, then au32, 64 bytes, then ani64: gaps at 22–23 and 92–95). The PR replaces the generic read with aResultBytestrait: scalars and handles encode their native bytes, andGameLicensewrites each field at itsoffset_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 (xgamesavepasses ani64and a handle) still fit the new bound. Minor: the diff also re-wraps a few unrelated lines inpending_with(rustfmt churn), which could be dropped. Merges cleanly, CIcheckpassing.Generated by Claude Code
@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 newresult_bytes_round_trip_scalars_and_handles).cargo test -p victory-hle --lib modules::xstore::: 4 passed, 0 failed (including newgame_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 on GitHub · 2026-11-26 16:05 UTC · original · approved these changes
Reviewed
454c69c9467e6972856d8d4ee868235a1ceeca23(merged cleanly onto63bcca43c6a00a758510398fa43096ce7e4f7df0) and verified on Windows 11 x64 (rustc 1.98.1MSVC).Audit
crates/victory-hle/src/modules/xasync.rs:918,:955: replacing the genericCopyraw-memory copy inbytes()with the explicitResultBytestrait removes undefined behavior from reading uninitialized struct padding, and thecompile_faildoctest ensures future padded records cannot bypass explicit encoding. All 7 existing callers acrossxgamesave,xnetworking,xpackage, andxstorefit cleanly.crates/victory-hle/src/modules/xstore.rs:167,:178:GameLicense::into_result_byteswrites all 8 fields viastd::mem::offset_of!into a zero-initialized 104-byte buffer, matching the#[repr(C)]layout (align == 8, fields at offsets0, 18, 19, 20, 21, 24, 28, 96) and deterministically zeroing both padding gaps (22..24and92..96).xasync.rsincludes a few unrelated rustfmt line wraps inpending_withand an existing test.Verification
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 passedcargo test -p victory-hle --doc: 1/1 passed (compile_faildoctest)offset_of!values (size == 104,align == 8) and pre-poisoned aMaybeUninit<GameLicense>storage slot with0xFFbefore writing only the fields:xasync::bytesstill emitted exact zero bytes at[22..24]and[92..96].View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.