hle/xg: validate subresource slice and pitches before creating copy slices #3321
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!3321
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3321"
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?
@SalmanBarkat on GitHub · 2026-11-26 17:49 UTC · original
SalmanBarkat:fix/xg-copy-bounds→main· +241 −31 · 1 files · 1 commits · openSummary
Hardens xg::copy_args, xg::copy_into, and xg::copy_from in crates/victory-hle/src/modules/xg.rs so subresource bounds, swizzle addressability, and linear/tiled byte spans are validated with checked arithmetic before constructing raw slices.
What Was Wrong
Previously, copy_args only checked plane and mip = subresource % c.mips, and computed linear = (depths - 1) * depth + (m.height - 1) * row + bytes with unchecked arithmetic. As a result, copy_into and copy_from entered unsafe ( iled.add(offset) and std::slice::from_raw_parts(_mut)) before Layout::tile / Layout::detile rejected:
ow or depth pitches (
ow < bytes, or depth < slice_bytes when depth > 1), or
CopyArgs also computed (p.offset + l.size) only for copy_into/copy_from to index planes[plane] again and subtract offset back out.
How It Was Resolved
Verification
cargo clippy -p victory-hle --all-targets --locked -- -D warnings: passed (0 warnings)cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings: passed (0 warnings)cargo test -p victory-hle --locked: passed (153 lib tests + 1 idelityfx + 1o_dll_planting, 0 failed, 0 ignored)
cargo xtask policy: passed (sset policy: 191 files ok)@Dukestar69 on GitHub · 2026-11-26 18:09 UTC · original · approved these changes
Reviewed the diff and verified locally on Windows 11 x64:
c.mips,slicebounds (slice == 0forTex3d,slice < l.slicesotherwise),l.addressable(), minimum row/depth pitches, checked span arithmetic, andisize::MAXslice limits before constructing raw slices cleanly hardensxgcopy operations.cargo test -p victory-hle --lib modules::xg:: -- --test-threads=1: 5 passed, 0 failed (includingcopy_args_and_copies_validate_bounds_before_slicing).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).
@oni-swr on GitHub · 2026-11-26 18:21 UTC · original
Independent CPU/WARP verification of #3321 at exact head
a3069f837a9969a7b760098ec1761c42a9d213ec. It merges cleanly onto main63bcca43c6a00a758510398fa43096ce7e4f7df0, and the PR's merge-base is that main commit. No code changes by me, and no physical GPU or game files were used.Environment: Windows 11 Pro 10.0.26200 x64, rustc/cargo 1.98.1, Windows SDK 10.0.26100.0 x64
dxil.dll1.8.2502.11 onPATH,VICTORY_WARP=1,VICTORY_D3D12_WARP=1,--test-threads=1,-j 4. The xg tests don't touch D3D12, so WARP anddxil.dllwere only set as a precaution.Code review (
xg::copy_args,copy_into,copy_from; no blocking findings):slice == 0, 2D and array requireslice < l.slices.mips == 0can no longer divide by zero.l.addressable()turns the unaddressable XOR swizzle intoUnsupported(E_NOTIMPL) before any slice is built.linear,tiledandoffsetare capped atisize::MAXbeforefrom_raw_parts.l.sizefromtiled.add(plane offset). That equals the old(offset + size) - offset, so there is no behavior change for valid input.computer(this)andcopy_args.finish_copylogsUnsupportedandInvalidatwarn!.Tests:
cargo test -j 4 -p victory-hle --lib xg -- --test-threads=1: 24 passed, 0 failed. This includes the newcopy_args_and_copies_validate_bounds_before_slicing.cargo test -j 4 -p victory-hle --lib -- --test-threads=1: 152 passed, 1 failed,modules::dstorage::tests::a_page_list_filled_after_its_request_starts. This failure is pre-existing and flaky. On main the same test fails 3/3 and the full lib run shows 151 passed, 1 failed. On the PR it passed 2 of 3 isolated reruns.cargo clippy -j 4 -p victory-hle --all-targets -- -D warnings: clean.cargo run -j 4 -p xtask -- policy:asset policy: 191 files ok.Control on
origin/main(fail-before / pass-after):Result-returningcopy_argsand the newoffsetfield: 6× E0599unwrap_erronOption, plus E0609. So it fails before and passes after, but only as a compile break from the API change.E_INVALIDARGor layout errors. I could not show a return-code difference between main and the PR for them.unsafeslice creation, not something I could show as a fixed misbehavior.Not tested: real titles or game memory, an actual out-of-bounds or
isize::MAX-sized buffer (I can't safely build one), any non-Windows host, the GPU/WARP shader suites (this PR doesn't touch them), and the full workspace test suite.AI-assisted: Claude Code (Claude Sonnet 5.5).
@borosf on GitHub · 2026-11-26 19:03 UTC · original
Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head
a3069f8:Result: victory-hle lib: exit 0, 153 passed / 0 failed, including the new copy_args_and_copies_validate_bounds_before_slicing test.
Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. Fully green on this machine.
Synthetic tests only; no game data used. Full log kept locally. — borosf
@fuzeofficlal on GitHub · 2026-11-26 20:40 UTC · original · approved these changes
LGTM —
copy_args,copy_into, andcopy_fromcleanly validate subresource bounds,addressable(), checked span arithmetic, andisize::MAXlimits before constructing raw slices, without rejecting valid layouts (includingdepth = 0on single-depth textures and block-aligned BC textures).Verified
cargo clippy --locked -p victory-hle --all-targets -- -D warnings(default &--all-features): clean.rustfmt --edition 2024: clean on all PR-touched hunks incrates/victory-hle/src/modules/xg.rs.cargo test --locked -p victory-hle --lib modules::xg:: -- --test-threads=1: 5 passed, 0 failed (includingcopy_args_and_copies_validate_bounds_before_slicing).cargo test --locked -p victory-hle --all-targets -- --test-threads=1: 153 lib + 2 integration tests passed, 0 failed.Minor non-blocking nits
crates/victory-hle/src/modules/xg.rs:392:offsetandtiledare each capped atisize::MAX; checkingoffset.checked_add(tiled)againstisize::MAXas well would cover the whole-texture allocation bound on 32-bit targets.xg.rs:949: the XORE_NOTIMPLcheck passes the same 1-byteonebuffer to bothsrcanddst; using separate buffers avoids potential aliasing/size assumptions if preflight ordering ever changes.xg.rs:973: in the stencil-plane round-trip test, asserting that plane 0 bytes remain untouched would directly verifya.offsetis applied in bothcopy_intoandcopy_from.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.