Fixed bug 2219 - BMP loader do not handle big BITMAPINFOHEADER structure
authorSam Lantinga <slouken@libsdl.org>
Thu, 07 Nov 2013 19:15:58 -0800
changeset 791344dc7926f62d
parent 7912 10eff60470b3
child 7914 a391318fa60f
Fixed bug 2219 - BMP loader do not handle big BITMAPINFOHEADER structure

Patrice Mandin

I encountered a problem trying to load a 8-bit paletted BMP file using SDL. This file was generated using GIMP 2.8. It has a big BITMAPINFOHEADER (0x6c bytes for biSize field), and thus the palette is incorrectly setup.
src/video/SDL_bmp.c
     1.1 --- a/src/video/SDL_bmp.c	Wed Nov 06 23:59:24 2013 -0800
     1.2 +++ b/src/video/SDL_bmp.c	Thu Nov 07 19:15:58 2013 -0800
     1.3 @@ -150,6 +150,8 @@
     1.4          biBitCount = SDL_ReadLE16(src);
     1.5          biCompression = BI_RGB;
     1.6      } else {
     1.7 +        const int headerSize = 40;
     1.8 +
     1.9          biWidth = SDL_ReadLE32(src);
    1.10          biHeight = SDL_ReadLE32(src);
    1.11          /* biPlanes = */ SDL_ReadLE16(src);
    1.12 @@ -160,6 +162,10 @@
    1.13          /* biYPelsPerMeter = */ SDL_ReadLE32(src);
    1.14          biClrUsed = SDL_ReadLE32(src);
    1.15          /* biClrImportant = */ SDL_ReadLE32(src);
    1.16 +
    1.17 +        if (biSize > headerSize) {
    1.18 +            SDL_RWseek(src, (biSize - headerSize), RW_SEEK_CUR);
    1.19 +        }
    1.20      }
    1.21      if (biHeight < 0) {
    1.22          topDown = SDL_TRUE;