From 8b57a0daf1f78cd20c7478db53c65336191de540 Mon Sep 17 00:00:00 2001 From: Longno242 Date: Tue, 24 Nov 2026 13:08:29 +0000 Subject: [PATCH] XGameRuntime: XAsyncGetResultSize writes 0 while the operation is pending libHttpClient always stores into *bufferSize before returning, including E_PENDING (typically 0). Leaving the caller's out-parameter untouched let a stale sentinel survive until GetResult. Assisted-by: Cursor Auto (Composer) Co-authored-by: Cursor --- crates/xcl/src/hle/xgameruntime/xasync.rs | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/crates/xcl/src/hle/xgameruntime/xasync.rs b/crates/xcl/src/hle/xgameruntime/xasync.rs index d358dc59c9..b739154b09 100644 --- a/crates/xcl/src/hle/xgameruntime/xasync.rs +++ b/crates/xcl/src/hle/xgameruntime/xasync.rs @@ -351,10 +351,14 @@ pub unsafe extern "system" fn XAsyncGetResultSize(b: *mut XAsyncBlock, size: *mu let f: unsafe extern "system" fn(usize, *mut XAsyncBlock, *mut usize) -> HRESULT = std::mem::transmute(f); return f(o, b, size); } + // libHttpClient always writes `*bufferSize` before returning, including E_PENDING (0). match lookup(b) { Lookup::Active(s) => { let g = s.inner.lock().unwrap(); if !g.is_done() { + if !size.is_null() { + *size = 0; + } return E_PENDING; } if !size.is_null() { @@ -363,7 +367,7 @@ pub unsafe extern "system" fn XAsyncGetResultSize(b: *mut XAsyncBlock, size: *mu g.status } Lookup::Finished(h) => { - if !size.is_null() && h.status >= 0 { + if !size.is_null() { *size = 0; } h.status @@ -761,6 +765,25 @@ mod tests { } } + /// libHttpClient always stores into `*bufferSize` before returning, including when the + /// operation is still pending (0). Leaving the caller's sentinel unchanged is a bug. + #[test] + fn get_result_size_writes_zero_while_pending() { + let _g = crate::hle::xgameruntime::xasync::ASYNC_TEST_LOCK.lock().unwrap_or_else(|e| e.into_inner()); + unsafe { + let mut b: XAsyncBlock = std::mem::zeroed(); + assert_eq!(XAsyncBegin(&mut b, std::ptr::null_mut(), std::ptr::null(), std::ptr::null(), begins_without_work as usize), S_OK); + let mut size = 0xDEADusize; + assert_eq!(XAsyncGetResultSize(&mut b, &mut size), E_PENDING); + assert_eq!(size, 0, "pending GetResultSize must write *size = 0"); + XAsyncComplete(&mut b, S_OK, 0); + assert_eq!(XAsyncGetStatus(&mut b, true), S_OK); + size = 0xBEEF; + assert_eq!(XAsyncGetResultSize(&mut b, &mut size), S_OK); + assert_eq!(size, 0); + } + } + /// A terminated queue takes no new async work: the call fails with E_ABORT through the /// block, and the work never runs. #[test]