GPU: reject overflowing FirstElement and NumElements arithmetic in buffer view creation #2539
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2541"
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 reeledMarek on 2026-11-25T15:33:43Z.
Problem
In
crates/victory-gpu/src/descriptor/host.rs,buffer_range,unordered_range,buffer_srv, andbuffer_uavcomputedaddress + buffer.FirstElement * elementandu64::from(buffer.NumElements) * elementwith uncheckedu64arithmetic.A large
FirstElement(such as1 << 60withStructureByteStride = 16, oru64::MAX) panics in debug builds and silently wraps in release builds before reachingwithin(), producing a bogusstartaddress. Additionally,buffer_rangeandunordered_rangedid not verifyViewDimension == BUFFERbefore reading theBufferunion member.Fix
checked_buffer_range(base, first, count, element)usingchecked_mulandchecked_add, rejecting anyu64overflow.desc.ViewDimension == D3D12_SRV_DIMENSION_BUFFER/D3D12_UAV_DIMENSION_BUFFERbefore accessingdesc.Anonymous.Buffer.Testing
overflowing_buffer_ranges_are_refusedincrates/victory-gpu/src/descriptor/host.rs.cargo test -p xtask --lockedpasses asset policy.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:34:07Z.
Automated triage for the maintainers.
Replaces the unchecked
base + FirstElement * element/NumElements * elementarithmetic inbuffer_range,unordered_range,buffer_srvandbuffer_uav(crates/victory-gpu/src/descriptor/host.rs) withchecked_buffer_range, and addsViewDimension == BUFFERchecks before the union read.As it stands, the value is unclear:
buffer_rangereaches it only for a buffer resource (buffer_bytes(..)?orresource[0] == 1), and D3D12 only allows buffer-dimension views on buffers. So the newViewDimensionchecks guard a case that cannot occur.FirstElement/NumElementscome from the title's own view descriptions. Release builds wrap, andshadow::for_view/within(which already saturates) then refuse the view. So the overflow only matters for a debug-build panic on a garbage descriptor.What would change the verdict: a real case where such a view reaches these functions, such as a log line from a run or a descriptor path where uninitialised words are read. Without one, this is a guard for a case that does not occur, and a maintainer may prefer to close it.
CI: passing.
Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T20:05:36Z.
Closing per triage — release builds wrap and
within()already rejects invalid buffer views without a concrete triggering title descriptor. Thanks for the review!Pull request closed