XGameRuntime: null out-pointers on result retrieval and lookup failures #1237
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1247"
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?
Imported from ivall/xcl. Originally posted by mahfuzinam0045-spec on 2026-11-24T13:42:08Z.
Under standard Win32, COM, and GDK conventions (
_COM_Outptr_,_Outptr_result_maybenull_, etc.), functions that produce output pointers or handles must set non-null out-pointer parameters to null (std::ptr::null_mut()) whenever the function fails or returns an error HRESULT.Previously, several asynchronous result retrieval functions (
XUserGetTokenAndSignatureResult,XUserGetTokenAndSignatureUtf16Result,XUserAddResult,XGameSaveInitializeProviderResult,install_chunks_result,mount_with_ui_result) and handle/object lookup functions (XUserFindUserByLocalId,XUserFindUserById,XUserDuplicateHandle,XPackageMount,XGameSaveCreateContainer,XGameSaveCreateUpdate,XTaskQueue*) left output pointers uninitialized on error. Callers that check the pointer after failure or have cleanup paths (e.g.if (ptr) ptr->Release()) can dereference uninitialized stack/heap memory or trigger access violations (as seen when auth token or live requests fail offline).This aligns these functions with existing implementations like
XNetworkingQuerySecurityInformationForUrlUtf16AsyncResult,XStoreCreateContext, andquery_interfacewhich already properly null out-pointers.What is in it
crates/xcl/src/hle/xgameruntime/mod.rs: initialize*ptr_to_buffer = std::ptr::null_mut()onXUserGetTokenAndSignatureResultandXUserGetTokenAndSignatureUtf16Result; null*outinXUserAddResult,XUserDuplicateHandle,XUserFindUserByLocalId,XUserFindUserById, andXPackageMount.crates/xcl/src/hle/xgameruntime/gamesave.rs: initialize*out = std::ptr::null_mut()onXGameSaveInitializeProviderResult,XGameSaveCreateContainer, andXGameSaveCreateUpdate.crates/xcl/src/hle/xgameruntime/taskqueue.rs: initialize*out = std::ptr::null_mut()onXTaskQueueCreate,XTaskQueueGetPort,XTaskQueueCreateComposite, andXTaskQueueDuplicateHandle.crates/xcl/src/hle/xgameruntime/api.rs: checkout.is_null()and set*out = 0oninstall_chunks_resultandmount_with_ui_result.mod.rs,gamesave.rs, andtaskqueue.rsverifying that on error, out-pointers pre-populated with non-null canary values (0xDEADBEEF) are properly nulled tostd::ptr::null_mut().Tested
crates/xcl/src/hle/xgameruntime/mod.rs(result_and_lookup_functions_null_outptrs_on_failure),gamesave.rs(gamesave_functions_null_outptrs_on_failure), andtaskqueue.rs(taskqueue_functions_null_outptrs_on_failure) asserting that out-pointers are consistently set tonull_mut()on error.Regression run
test-onlylabel waiver.Not tested
AI use
Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T13:51:31Z.
Regression run for this PR: head
bc44eee, based onmain47efa2e. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release,XCL_NETWORK=0, A pressed every 4 s from 20 s,scripts/smoke.ps1on a retail title for 60 s.main
47efa2e:this PR:
No device removals or crashes; 95 % of main's frames, 103 % of its peak commit.
Not tested: the whole suite; the PR's new tests; whether the title hits these failure paths in 60 s.
Written with Claude Code (Claude Opus 5.5) from runs on this machine.
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:59:48Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib xgameruntime: 75 passed, 1 failed — the PR's own new test fails deterministically:One of the result-retrieval paths returns S_OK (0) where the test expects E_INVALIDARG (0x80070057) — the null out-pointer isn't being rejected on that path. Everything else in the area passes.
Imported from ivall/xcl. Originally posted by mahfuzinam0045-spec on 2026-11-24T16:31:55Z.
Thank you @DavidM1911 and @Anon64!
We traced why
XTaskQueueGetPort(std::ptr::null_mut(), ...)returnedS_OK: in GDK and XCL's implementation, passingnullreferences the valid default process task queue (queue_from(queue)delegates toprocess_queue()).In commit
c0530cc, we updated the test assertion to pass an invalid non-null handle (0x1234 as *mut c_void) and an out-of-range port index (99). Both error paths returnE_INVALIDARGas expected and verify that the out-pointers are nulled tostd::ptr::null_mut().All unit tests in
crates/xcl/src/hle/xgameruntime/taskqueue.rsnow pass cleanly.Imported from ivall/xcl. Originally posted by Toons29 on 2026-11-25T03:18:57Z.
Regression run of
c0530ccbon the retail title, for this PR's Regression run section. Both blocks are fromscripts/smoke.ps1as printed, not edited:mainon4178e888, this PR on its head commit with no uncommitted changes, same title and time.Against the limits in CONTRIBUTING.md: 100 % of
main's frames, 100 % of its peak commit, no crash, no device removal.AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0,
cargo build --release -p xcl, 60 s,XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.AI use: Claude Code (Claude Opus 5.5) built both trees and ran
scripts/smoke.ps1; I checked the blocks before posting.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:32:33Z.
Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current
mainon the new head — needs another rebase before it can be tested.Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-12-01T02:31:37Z.
Nothing has happened on this PR for 3 days, so it is marked
staleand will be closed in 4 days. A push or a comment takes the mark off: rebase it ontomainif it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:13:47Z.
Triage (#1607) – head
c0530ccNo open or merged PR makes the same change: the result and lookup functions it touches (
XUserFindUserByLocalId,XTaskQueueCreate,XGameSaveCreateContainer,install_chunks_result, …) do not null their out-pointer on failure on main.The diff writes null only after checking the out-pointer itself, and the tests pass invalid handles that
queue_fromlooks up in its handle set before dereferencing. #1242 changesmount_with_ui_asyncright next tomount_with_ui_resulthere; expect a textual conflict.The PR conflicts with main and its checks failed on this head.
Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.