DentonW / DevIL

Developer's Image Library (DevIL) is a cross-platform image library utilizing a simple syntax to load, save, convert, manipulate, filter, and display a variety of images with ease. It is highly portable and has been ported to several platforms.
http://openil.sourceforge.net/
GNU Lesser General Public License v2.1
446 stars 137 forks source link

ilCopyPixels crashes loading RGBA-paletted bmps as luminance images #56

Open TheHugeManatee opened 7 years ago

TheHugeManatee commented 7 years ago

ilCopyPixels() will crash when copying a bmp image with an RGBA/BGRA-palette as IL_LUMINANCE

Debugging shows this is a problem of iConvertPalette(), where a palette with bpp=4 is not treated correctly, causing an integer to underflow.

sample image is attached. test.zip

TheHugeManatee commented 7 years ago

See https://github.com/TheHugeManatee/DevIL/commit/a951650e59ca575d6f5bdca9fc84e47ce0b66e8c for a possible fix. This would do fine for now, preventing j to underflow for Size >= 4 but will not be robust for color palettes with bpp other than 3 or 4. Currently, ilGetBppPal() only returns 0, 3 or 4, where 0 still will result in an indefinite loop..