HLE (xg): validate null tiling output, slice bounds, and checked copy spans #674
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/674"
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 DenRakEiw on 2026-11-24T06:37:46Z.
## Summary
Fixes memory-safety / bounds-validation issues in
crates/victory-hle/src/modules/xg.rs:outintilingwhen*count > 0:tilingpreviously wrote entries toout.add(i as usize).write(entry)without checkingout.is_null(), causing null-pointer write UB when a caller passed*count > 0and a nulloutbuffer.E_INVALIDARGupfront before mutating any output pointers whencountis non-null with*count > 0andout.is_null()(while still allowing*count == 0with nullout).standard.saturating_mul(slices)when computingwanted.slice < l.slicesand use checked span arithmetic incopy_args:copy_argspreviously checkedmipbounds vial.mips.get(mip)but did not checkslice < l.slices, allowingcopy_into/copy_fromto construct raw slices from caller pointers for out-of-range subresources beforeLayout::tile/Layout::detilerejected the slice.slice < l.slices, uses checked arithmetic (checked_sub,checked_mul,checked_add,usize::try_from) for linear and tiled spans, and ensures slice lengths stay withinisize::MAX.Tests
Added 2 synthetic unit tests in
crates/victory-hle/src/modules/xg.rs:tiling_rejects_null_out_when_count_nonzerocopy_rejects_out_of_range_slice_and_planeVerification
cargo test -p victory-hle xg: 15 passed, 0 failed (all 6modules::xg::testspassed)cargo clippy -p victory-hle --all-targets: 0 warnings inxg.rscargo xtask policy: okAI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T06:50:20Z.
Review: APPROVED
LGTM! Tested on Windows 11 with MSVC Rust 1.98.1. All 88 tests in ictory-hle passed cleanly, including both new tests in modules::xg::tests ( iling_rejects_null_out_when_count_nonzero and copy_rejects_out_of_range_slice_and_plane). Validating out nullness upfront and checking slice bounds prevents out-of-bounds slicing and undefined behavior in texture tiling.
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T06:56:25Z.
Review: COMMENTED
Static review only (victory-hle doesn't build off Windows):
This is a solid hardening pass on the tiled-copy path:
copy_argsnow carriestiled_offset/tiled_lenexplicitly instead of the end offset re-derived by callers — removes the duplicatedplanes[plane].offsetfetch and thea.tiled - offsetsubtraction.slice >= l.slicescheck closes a real gap:mipwas bounds-checked vial.mips.get(mip)butslicewas not.checked_mul/checked_add/try_from) replaces wrappingusizemath on title-controlleddepth/row/width— old code could overflow on 64-bit with large u32 inputs, and theisize::MAXguards make the subsequentslice::from_raw_partsoffsets sound.tiling()returningE_INVALIDARGforcount > 0 && out.is_null()matches the usual D3D-style contract.One nit:
usize::try_from(m.width)wherewidth: u32is infallible on 64-bit — harmless, just slightly noisy. No objections otherwise.Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T09:38:40Z.
Independent verification of
b9e5f2e9fmerged withmain(8e79c80, clean merge) on Windows 11 Pro (26100), Rust1.98.1(x86_64-pc-windows-msvc), AMD Radeon RX 9060 XT: PASS.cargo xtask policy→asset policy: 153 files okcargo clippy --workspace --all-targets --locked -- -D warnings→ pass (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings→ pass (0 warnings)cargo test --workspace --locked→ 313 passed, 0 failed, 6 ignored (both newmodules::xg::tests::tiling_rejects_null_out_when_count_nonzeroandcopy_rejects_out_of_range_slice_and_planepass)copy_argsnow validatesslice < l.slices, checks linear/tiled span arithmetic against overflow andisize::MAXbeforefrom_raw_parts(_mut), andtilingrejects*count > 0 && out.is_null()upfront without mutating caller outputs while still permitting*count == 0with nullout.AI-assisted; synthetic tests only, no game files.
Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:39:03Z.
Review: APPROVED
Tested
b9e5f2eon Windows 11, RTX 5070, MSVC:cargo test -p victory-hle89 passed, includingtiling_rejects_null_out_when_count_nonzeroandcopy_rejects_out_of_range_slice_and_plane. Clippy shows 1field_reassign_with_defaultwarning at xmem.rs:747, which this PR doesn't touch.copy_argsnow checkssliceagainstl.slicesand does all the span arithmetic with checked operations, so a bad subresource fails withE_INVALIDARGbefore anyfrom_raw_partscall. Carryingtiled_offset/tiled_leninstead of recomputingend - offsetat the call sites also removes the chance of an underflow there.outcheck intilingruns before any output is written, and the test confirms that a failed call leavestilesandcountuntouched.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by ErRusso on 2026-11-24T11:23:32Z.
Audit: ✅ Looks good (needs Windows to compile the GPU-dependent crate)
Reviewed this PR as part of an audit of mergeable PRs.
crates/victory-hle/src/modules/xg.rs(+113/-13). Three improvements: (1) all arithmetic incopy_args()useschecked_mul,checked_add,checked_sub, and caps values atisize::MAX; (2)tiling()rejects nulloutwhen*count > 0; (3)slice >= l.slicesearly-return prevents out-of-range subresource access. Also fixes astandard * slicesmultiplication that could overflow by usingsaturating_mul.main.#[cfg(windows)]gating gap), so the newtiling_rejects_null_out_when_count_nonzeroandcopy_rejects_out_of_range_slice_and_planetests couldn't run here. The logic is sound on review.CopyArgsnow storestiled_offset+tiled_leninstead of derivingtiled - offsetat each call site — cleaner and the safety fix in one place.No issues found.
Imported from Marvisak/VIctory. Originally posted by molodayamama on 2026-11-24T14:02:24Z.
Independent Windows check of
b9e5f2e9ff3d03c1cc3f89402aacbb63eb4c559e(Windows 10 22H2 19045, Rust 1.98.1, MSVC x64).cargo test -p victory-hle --locked --lib tiling_rejects_null_out_when_count_nonzero -- --test-threads=1 --nocapture: 1 passed.cargo test -p victory-hle --locked --lib copy_rejects_out_of_range_slice_and_plane -- --test-threads=1 --nocapture: 1 passed.The new XG fixtures check rejecting a null tiling-output pointer for a nonzero count, and refusing out-of-range slices and planes before a texture copy. No GPU execution.
Only source-built synthetic fixtures were used. AI-assisted verification.
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:28:50Z.
Automated triage for the maintainers.
Proposed close. This PR adds bounds checks to
crates/victory-hle/src/modules/xg.rs, but what they guard against is already handled onmainor cannot occur:copy_into/copy_frombuild the tiled slice over the whole plane (p.offset .. p.offset + l.size), whatever the slice. Nothing is read or written beforeLayout::walkincrates/victory-formats/src/texture.rsrejectsfirst >= self.sliceswithError::Invalid(soE_INVALIDARG). The new check returns the same result one step earlier.u32values and our own layout's sizes, so they cannot overflow a 64-bitusize.Layout::walkalready checks the linear span against the buffer with checked arithmetic.outwith*count > 0intiling: this is a call a title does not make, andstandard(at most the mip count) timesslicescannot overflow.What would change the verdict: a concrete input that reaches out-of-bounds memory on
main.CI: no check runs on the head commit.
This pull request 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 DenRakEiw on 2026-11-25T02:57:51Z.
Makes sense —
Layout::walkalready rejectsfirst >= self.sliceswithE_INVALIDARGbefore touching the buffers, and theu32span terms cannot overflow 64-bitusize. Closing this PR to keep the queue clean. Thanks for the clear triage!AI-assisted (Gemini 4 Neon).
Pull request closed