From 0a9773c75cf79b5b990a68307fea7f9809467371 Mon Sep 17 00:00:00 2001 From: xezon <4720891+xezon@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:51:00 +0200 Subject: [PATCH] Fix dds file buffer overrun --- src/w3d/renderer/ddsfile.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/w3d/renderer/ddsfile.cpp b/src/w3d/renderer/ddsfile.cpp index 20dcc4690..60d597907 100644 --- a/src/w3d/renderer/ddsfile.cpp +++ b/src/w3d/renderer/ddsfile.cpp @@ -388,9 +388,10 @@ bool DDSFileClass::Get_4x4_Block(uint8_t *dst_ptr, // Gen and ZH only handle DXT1 and DXT5 switch (m_format) { case WW3D_FORMAT_DXT1: { - int offset = (src_x / 4) * 8 + ((src_y / 4) * (Get_Width(level) / 4)); + int offset = (src_x / 4) + ((src_y / 4) * (Get_Width(level) / 4)); unsigned dst_pixel = 0; uint8_t *block_mem = &Get_Memory_Pointer(level)[8 * offset]; + uint32_t color_a = Decode_Packed_565(block_mem); uint32_t color_b = Decode_Packed_565(block_mem + 2); // uint32_t code = Decode_Line_Code(block_mem + 4); @@ -479,7 +480,7 @@ bool DDSFileClass::Get_4x4_Block(uint8_t *dst_ptr, } return has_alpha; case WW3D_FORMAT_DXT5: { - int offset = (src_x / 4) * 16 + ((src_y / 4) * (Get_Width(level) / 4)); + int offset = (src_x / 4) + ((src_y / 4) * (Get_Width(level) / 4)); unsigned dst_pixel = 0; uint8_t *block_mem = &Get_Memory_Pointer(level)[16 * offset];