Avoid overflow when calculating ptr address for 3D textures in RenderingDevice texture update #74526
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes: #74173
image_size * z
could easily overflow with 3D textures even at modest sizes. For 2D textures z is always 0 so this never overflowed. This bug essentially breaks all 3D textures with a size larger than 256x256x256 with FORMAT_L8.In the linked issue image size was
33,554,432
(W x H x D x 1bit) since all values wereuint32_t
s this caused the calculation to overflow whenever z was a multiple of 64. With higher bit depths the overflow happens more frequently. Sincez / depth
is always less than one andimage_size
is always a multiple ofdepth
we can swap the order of operations to keep the values within a manageable range.