Repository navigation
fix(resource_tiling): guard integer overflows, shape divide-by-zero, and mip shift UB - #1980
Conversation
Flyander
left a comment
There was a problem hiding this comment.
Reviewed the changed arithmetic and bounds checks at the current head. I found no concrete correctness issue; the guards keep the division and shifts defined, and the added regression cases cover the affected input classes. CI is still pending.
|
Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): no regression from this PR. RTX 4080 SUPER: 111/113 pass. On current |
Summary
Fixes three arithmetic bugs in
resource_tiling()(runtime/src/resource_tiling.h):> 0xffffffffuguard:standard_tiles += tw * th * td,packed_bytes += ..., andper_slice * layerswere computed in uncheckeduint64_tarithmetic, allowing large dimensions to wrap modulo 2^64 (e.g.,2^25 * 2^25 * 2^14 == 2^64 == 0) and returntruewithtotal_tiles == 0. Also replaced(value + by - 1) / bywith overflow-safevalue ? 1 + (value - 1) / by : 0and ensuredoutstays clean on failure.shapeoverflow leading to integer divide-by-zero:elements.width * desc.blockandelements.height * desc.blockmultiplied inuint32_t, overflowing to0for largedesc.block(e.g.1u << 26with 16-byte elements) and crashing inup(w, out.shape.width).mip >= 32:desc.height >> mipanddepth >> mipshifteduint32_tby>= 32(clamped to1uformip >= 32, andwclamped to1formip >= 64).Regression Test (Fail-First)
Added regression cases in
runtime/test/resource_tiling_test.cpp:Debug): failed on{TiledKind::texture2d, 1ULL << 31, 1u << 31, 16384, 1, 16, 1}(line 201,EXIT=1; and{..., block = 1u << 26}divides by zero).Debug+RelWithDebInfo):resource_tilingandd3d12_vulkan_device(RTX 4070 Ti +LEONIDA_VK_VALIDATION=1) pass 2/2 in both configs with zero warnings and zero Vulkan validation errors.