draw.rs rectangle-list fallback: u32 first + count wraps before the bounds check; SizeInBytes can truncate #223

Open
opened 2026-11-26 11:59:50 +00:00 by kekonn · 0 comments
kekonn commented 2026-11-26 11:59:50 +00:00 (Migrated from github.com)
Contributor

Imported from avatarmanz/VIctory-7900XTX. Originally posted by kekonn on 2026-11-26T11:59:50Z.


crates/victory-gpu/src/draw.rs:3805: || u64::from(first + count) * stride > u64::from(v.size) adds the two values in u32 before widening. Release builds (and diag, which inherits them) don't check for overflow, so the sum wraps and the bounds check can pass. Further down, SizeInBytes: (rects * 6 * stride) as u32 (~3836) can truncate.

The damage is limited: shadow::find(from, rects*3*stride) (3806) still requires a registered title buffer covering the whole range. This is hardening, not a crash anyone has seen.

When: only the CPU fallback for RECTANGLES pipelines that did not get the rectangle geometry stage. It also needs a direct draw with first + count >= 2^32, or a range of 4 GiB or more.

Proposed fix (~4 lines)

Compute (u64::from(first) + u64::from(count)) * stride, and build SizeInBytes with u32::try_from(…), returning false on overflow.

Upstream: no open PR changes rectangles(). #53 adds a diagnostics hunk just above it.
Status: a fix is being prepared in kekonn/VIctory-7900XTX on branch claude/gifted-clarke-uxuqw8.


Generated by Claude Code

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6626180857 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/issues/223). Originally posted by [kekonn](https://github.com/kekonn) on 2026-11-26T11:59:50Z. --- `crates/victory-gpu/src/draw.rs:3805`: `|| u64::from(first + count) * stride > u64::from(v.size)` adds the two values in `u32` before widening. Release builds (and `diag`, which inherits them) don't check for overflow, so the sum wraps and the bounds check can pass. Further down, `SizeInBytes: (rects * 6 * stride) as u32` (~3836) can truncate. The damage is limited: `shadow::find(from, rects*3*stride)` (3806) still requires a registered title buffer covering the whole range. This is hardening, not a crash anyone has seen. **When:** only the CPU fallback for RECTANGLES pipelines that did not get the rectangle geometry stage. It also needs a direct draw with `first + count >= 2^32`, or a range of 4 GiB or more. ### Proposed fix (~4 lines) Compute `(u64::from(first) + u64::from(count)) * stride`, and build `SizeInBytes` with `u32::try_from(…)`, returning `false` on overflow. **Upstream:** no open PR changes `rectangles()`. #53 adds a diagnostics hunk just above it. **Status:** a fix is being prepared in kekonn/VIctory-7900XTX on branch `claude/gifted-clarke-uxuqw8`. --- _Generated by [Claude Code](https://claude.ai/code)_
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
avatarmanz/VIctory-7900XTX#223
No description provided.