HLE (xg): validate null tiling output, slice bounds, and checked copy spans #674
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!674
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/674/head"
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?
@DenRakEiw on GitHub · 2026-11-24 06:37 UTC · original
fix/xg-tiling-and-copy-bounds→main· +113 −13 · 1 files · 1 commits · closed without merging## 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).
@geiyiliyabumo on GitHub · 2026-11-24 09:38 UTC · original
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.
@ErRusso on GitHub · 2026-11-24 11:23 UTC · original
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.
@molodayamama on GitHub · 2026-11-24 14:02 UTC · original
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.
@Marvisak on GitHub · 2026-11-25 01:28 UTC · original
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
@DenRakEiw on GitHub · 2026-11-25 02:57 UTC · original
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