HLE XG: reject null output buffer when *count > 0 in GetResourceTiling #3070
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3072"
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 Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T06:26:01Z.
Summary
Guards against a null-pointer dereference in
XGTextureAddressComputer::GetResourceTiling(tiling, vtable slot0x50) when a caller passes a non-nullcountwith*count > 0and a nulloutbuffer, returningE_INVALIDARGbefore writing any output parameters.Why
In
crates/victory-hle/src/modules/xg.rs,tilingchecked every other optional output pointer (tiles,packed,shape,count) via.as_mut(), but never checkedout: *mut SubresourceTilingfor null. On any 64 KiB tiled texture with at least one standard mip, passing*count > 0without == nullexecutedout.add(i as usize).write(entry)through a null pointer (access violation / UB). Passing*count == 0without == nullremains accepted (S_OK, writing 0 entries).Verification
modules::xg::tests::tiling_rejects_null_out_when_count_nonzeroverifying:*count > 0without == nullreturnsE_INVALIDARGwithout mutatingtilesorcount.*count == 0without == nullreturnsS_OKand still fillstiles.cargo test -p victory-hle xg::tests: 5 passed, 0 failed.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).
Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T06:32:44Z.
Review: APPROVED
Verified: *count>0 + null out -> E_INVALIDARG before any output write (tiles/count untouched, asserted); *count==0 + null out stays valid and returns S_OK with 0 entries. Matches XG semantics.
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:03:40Z.
Review: CHANGES_REQUESTED
Tested locally on Windows 11 x64 (
rustc 1.98.1):cargo clippy -p victory-hle --all-targets --locked -- -D warnings: clean.cargo test -p victory-hle --locked: 153 lib + 1 fidelityfx + 1 no_dll_planting passed, 0 failed.One aliasing edge case remains in
tiling(crates/victory-hle/src/modules/xg.rs:487-537):*countto decide whetherout.is_null()is allowed, thenif let Some(t) = tiles.as_mut()writes*t = (l.size / TILE) as u32(e.g.2for the existing BC7 fixture), and finally the loop re-reads*countto computewanted = (standard * slices).saturating_sub(first).min(*n).tilesandcountto the same initially zerou32while passingout == null, the entry check sees0and passes, writing*tilesmutates*countto a nonzero tile count, and the loop then writes through a nullout.Reading the input capacity from
*countonce into a local variable before writing any output parameters—and using that saved capacity for both the null-outcheck andwanted—closes this cleanly. Please also add a unit test covering the aliasedtiles == countzero-capacity case.Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T08:19:21Z.
Good catch @fuzeofficlal, thanks! Fixed in
0d546b2:capacityfrom*countonce up front before writing any output pointers, and use that savedcapacityfor both the null-outguard andwanted.tiles == countzero-capacity with nulloutregression check totiling_rejects_null_out_when_count_nonzero.cargo test -p victory-hle --locked(153 lib + 2 integration passed),cargo clippy -p victory-hle --all-targets --locked -- -D warnings(clean), andcargo xtask policy(191 files ok).Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:23:28Z.
Automated triage for the maintainers.
Verdict: proposed close. The new check in
tiling(modules/xg.rs, slot 0x50) guards against a caller passing room for*count > 0entries with a nullout. That breaks the method's own contract, and there's no sign the title does it. The module states its stance at the top: "Title code passes pointers the real library would trust", andtiling's SAFETY comment saysouthas room for*countentries.The PR also picks
E_INVALIDARGas the console library's answer with no evidence of what the library returns. A guard for an impossible case with an invented return value isn't something the repo takes.What would change this: evidence that the title (or another real caller) makes this call, and of what the console library returns for it.
CI: not run on this head.
This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the
triage: proposed closelabel.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T09:31:59Z.
Closing per triage feedback:
modules/xg.rsintentionally trusts caller contracts and there is no evidence of a title passing*count > 0without == null. Thanks for the review! Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).Pull request closed