bimg icon indicating copy to clipboard operation
bimg copied to clipboard

imageConvert from BC3 to RGBA32F with mipmap cause memory writen out of bounds

Open junjie020 opened this issue 1 year ago • 0 comments

I have a BC3 format texture with mipmaps, and I want to convert it to RGBA32F format with mipmaps. It will cause memory writen out of bounds (The texture I tested is attached in this issue).

Compile texturec tools, and run this command line: > texturecDebug -f {yourdir}/test_BC3.dds -o {outputdir}/out_RGBA32F.dds -t RGBA32F -q fastest --mips

It will throw an exception in this code line: https://github.com/bkaradzic/bimg/blob/master/src/image.cpp#LL4465C32-L4465C32

(The heap is broken right now)

The reason I found in the code: https://github.com/bkaradzic/bimg/blob/master/src/image.cpp#L1284

The attach file is BC3 format with mipmaps, it's resolution is 8x8. In mip level 2, the resolution should be 2x2, but the lowest block size of BC3 format is 4x4, so imageGetRawData function return m_width and m_height in var mip are 4. But RGBA32F format resolution in mip level 2 must be 2x2, then it will cause memory writen out of bounds.

test_BC3.zip

junjie020 avatar Jun 20 '23 06:06 junjie020