From 643d5cfdd8bd21802c17fc9a95e42fe52f1e5a88 Mon Sep 17 00:00:00 2001 From: eranzhao Date: Wed, 11 Dec 2024 21:20:20 +0800 Subject: [PATCH] Fix overflow when texture size is smaller than block size If the texture size is smaller than the block size, it can cause an overflow. For example, a texture size of 4x4 with a format of ASTC 6x6. --- renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp b/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp index 6f9e50a251..16e10a8374 100644 --- a/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp +++ b/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp @@ -3813,7 +3813,7 @@ void WrappedOpenGL::StoreCompressedTexData(ResourceId texId, GLenum target, GLin // GetCompressedByteSize() will factor in the 'partial' blocks at image edges when the // image size is not an integer multiple of the block size, so we need to take into // account that in the loop - size_t roundedUpHeight = AlignUp((uint32_t)height, blockSize[1]); + size_t roundedUpHeight = (uint32_t)height < blockSize[1] ? (uint32_t)height : AlignUp((uint32_t)height, blockSize[1]); for(size_t y = 0; y < roundedUpHeight; y += blockSize[1]) { memcpy(cdData.data() + dstOffset, srcPixels + srcOffset, srcRowSize);