gpu: avoid shift overflow in resource::subresource on large mip levels #41

Merged
ahmetbagci8 merged 1 commit from upstream-pr/41 into dev 2026-11-29 20:55:31 +00:00
ahmetbagci8 commented 2026-11-29 18:12:03 +00:00 (Migrated from github.com)

Imported from edsuuu/VI-BR-PORT. Originally posted by ahmetbagci8 on 2026-11-29T18:12:03Z.


Problem

In crates/victory-gpu/src/resource.rs, subresource() shifts desc.width >> mip, u64::from(desc.height) >> mip, and (for 3D textures) u32::from(desc.depth_or_array_size) >> mip without bounding mip. When mip_levels is large (mip >= 32 for 3D depth or mip >= 64 for width/height), this panics with shift overflow in debug builds and wraps modulo 32/64 in release builds.

Fix

Use .checked_shr(mip).unwrap_or(0).max(1) for width, height, and 3D depth, and add unit test subresource_with_large_mip_does_not_overflow_shift.

Verification

  • cargo test -p victory-gpu --lib subresource_with_large_mip_does_not_overflow_shift (1 passed, 0 failed)
  • cargo clippy -p victory-gpu --tests (0 warnings)
<!-- greyfinch-sync:edsuuu/VI-BR-PORT:issue:5553613312 --> Imported from [edsuuu/VI-BR-PORT](https://github.com/edsuuu/VI-BR-PORT/pull/41). Originally posted by [ahmetbagci8](https://github.com/ahmetbagci8) on 2026-11-29T18:12:03Z. --- ## Problem In crates/victory-gpu/src/resource.rs, subresource() shifts desc.width >> mip, u64::from(desc.height) >> mip, and (for 3D textures) u32::from(desc.depth_or_array_size) >> mip without bounding mip. When mip_levels is large (mip >= 32 for 3D depth or mip >= 64 for width/height), this panics with shift overflow in debug builds and wraps modulo 32/64 in release builds. ## Fix Use .checked_shr(mip).unwrap_or(0).max(1) for width, height, and 3D depth, and add unit test subresource_with_large_mip_does_not_overflow_shift. ## Verification - cargo test -p victory-gpu --lib subresource_with_large_mip_does_not_overflow_shift (1 passed, 0 failed) - cargo clippy -p victory-gpu --tests (0 warnings)
Sign in to join this conversation.
No reviewers
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
edsuuu/VI-BR-PORT!41
No description provided.