GPU: avoid shift and arithmetic overflow panics in subresource and copyable_footprints (victory-gpu) #1543
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!1543
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1543"
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?
@Texbirds on GitHub · 2026-11-24 18:58 UTC · original
Texbirds:fix/gpu-subresource-shift-overflow→main· +138 −23 · 1 files · 1 commits · openProblem
In
crates/victory-gpu/src/resource.rs,subresourceandcopyable_footprintsperform unchecked shifts and alignment/offset arithmetic on title-supplied values:u32::from(desc.depth_or_array_size) >> mippanics for 3D textures whenmip >= 32;desc.width >> mipandu64::from(desc.height) >> mippanic whenmip >= 64(sincemip_levelsis an unboundedu16).desc.width.next_multiple_of(PITCH),row_size.next_multiple_of(PITCH),first + i,end.next_multiple_of(PLACEMENT), and offset/line multiplications panic or wrap on extreme widths,first, orbaseinstead of returning the documented all-ones sentinel (NO_FOOTPRINT,u32::MAX,u64::MAX).Fix
checked_shr(mip).unwrap_or(0)for mip extent shifts andchecked_next_multiple_of/checked_add/checked_mulinsubresourceandcopyable_footprints.copyable_footprints_handles_large_mips_and_overflows_without_panicking.Verification
windows-latestCI (cargo clippydefault +--all-featuresandcargo test --workspace --locked).@acetonahard-code on GitHub · 2026-11-24 22:28 UTC · original
Tested on Windows 11, RTX 4070 SUPER (driver 621.14), with the repo toolchain, merged into current
main(70564ae):cargo test -p victory-gpumainmain+ this PRmain,--all-featuresmain+ this PR,--all-featurescargo clippy --all-targets -- -D warnings, with and without--all-features: clean.cargo fmt --checkwould rewrap 5 blocks this PR adds (resource.rs).mainisn't rustfmt-clean either, so take it or leave it.victory-gputests fail on currentmainon this NVIDIA card:dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_views. That's the 1,000,000-view heap cap, see #1744. They fail the same way with this PR, and no other test does.I didn't test with game data.
Tested locally with an AI-assisted script (Claude Code); I checked the results before posting.
@Marvisak on GitHub · 2026-11-25 01:30 UTC · original · edited 2026-11-25 12:25 UTC
Automated triage for the maintainers.
Merge candidate. Thanks for
15f1999. The mip handling now follows the module's contract. Incrates/victory-gpu/src/resource.rs,subresourcereturnsNonewhenmip_countexceedsfull_mip_count(the same full-chain computation as before, factored out) or when a shift overflows.copyable_footprintsthen reports the documented all-ones values. The test now asserts that sentinel for 3Dmip=32, 2Dmip=64and one-past-the-chain descriptions, instead of a 1×1×1 footprint.The checked arithmetic for the index, base offset, buffer width and row pitch is unchanged from the last review and fine.
full_mip_countgives the same result asmain's0branch, so valid descriptions behave exactly as before. CIcheckpasses at15f1999.For the maintainers: none of these inputs come from a valid description, so this is robustness (no panic inside an
extern "system"function), not a fix for an observed crash.Generated by Claude Code
@Texbirds on GitHub · 2026-11-25 12:15 UTC · original
Updated in
15f1999(CIcheckis passing):subresourcenow returnsNonewhenmip_count(desc)exceedsfull_mip_count(desc)(the full chain from the0branch) or whenchecked_shr(mip)overflows, so invalid mip descriptions produce the documented(NO_FOOTPRINT, u32::MAX, u64::MAX)/u64::MAXsentinel instead of clamping to 1×1×1.copyable_footprints_handles_large_mips_and_overflows_without_panickingto assert the all-ones sentinel for 3D (mip=32), 2D (mip=64), and one-past-full-chain (16x16,mip_levels=6) descriptions as well as index, base-offset, and buffer-width overflows.@fuzeofficlal on GitHub · 2026-11-26 13:32 UTC · original · approved these changes
Reviewed and verified
15f1999dmerged locally ontoorigin/main(63bcca43) on Windows 11 x64 (NVIDIA GeForce RTX 5090 and WARP, Rust1.98.1MSVC, Windows SDK10.0.26100.0dxil.dll; synthetic tests only, no game files).Verification
git merge-treeagainstorigin/main(63bcca43): clean.cargo xtask policy(PR head):182 files ok.cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--all-features, PR head and merged): 0 warnings.VICTORY_D3D12_DEBUG=1,--features diagnostics, merged):resource::tests+draw::tests— 39 passed, 0 failed on both adapters (includingcopyable_footprints_handles_large_mips_and_overflows_without_panicking).--release, merged):resource::tests+draw::tests— 39 passed, 0 failed.Review Notes
full_mip_count(crates/victory-gpu/src/resource.rs:296-308) and rejectingmips > full_mip_count(desc)(:364-366) together withchecked_shr(mip)?(:384-395) and checked alignment/offset arithmetic (:359,:387-398,:430-446) eliminates unchecked shift and arithmetic panics across anextern "system"FFI entry point while preserving identical results for every valid resource description.NO_FOOTPRINT,u32::MAX,u64::MAX).#1543and#1984touch the same extent-shift lines insubresource(resource.rs), so whichever lands second will need a small merge (checked_shr(extent_shift)?).Looks good to merge.
@Dukestar69 on GitHub · 2026-11-26 19:30 UTC · original · approved these changes
LGTM — verified on Windows against
origin/main(63bcca4).mips <= full_mip_count(desc)and usingchecked_shr/checked_next_multiple_of/checked_mul/checked_addacrosssubresourceandcopyable_footprintscleanly prevents panics across the FFI boundary and returns the documented D3D12 all-ones sentinel on invalid/overflowing inputs.cargo test -p victory-gpu --lib resource:: -- --test-threads=1: 19 passed, 0 failed (includingcopyable_footprints_handles_large_mips_and_overflows_without_panicking).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
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.