Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid overflow when calculating ptr address for 3D textures in RenderingDevice texture update #74526

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

clayjohn
Copy link
Member

@clayjohn clayjohn commented Mar 7, 2023

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 were uint32_ts this caused the calculation to overflow whenever z was a multiple of 64. With higher bit depths the overflow happens more frequently. Since z / depth is always less than one and image_size is always a multiple of depth we can swap the order of operations to keep the values within a manageable range.

@clayjohn clayjohn added this to the 4.1 milestone Mar 7, 2023
@clayjohn clayjohn requested a review from a team as a code owner March 7, 2023 00:20
@akien-mga akien-mga merged commit c82948a into godotengine:master Mar 7, 2023
@akien-mga
Copy link
Member

Thanks!

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.0.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Large Texture3D gets Corrupted
3 participants