diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-08-27 15:59:26 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-08-27 15:59:26 +0400 |
commit | 590251f55a113848043c8eb43563379f614f65f3 (patch) | |
tree | 1994ed90524d7f3bdfdb2e874ed7bd9678fe2e8a /source/blender/imbuf/intern/bmp.c | |
parent | 13254cde8c7ca38af2dcec35efdb9f8f9b3bca46 (diff) |
File format fixes
- Add check for header field in BMP decoder. This is needed to distinguish
whether file is indeed BMP image or not.
Without this check Blender could easily crash when it'll try to load
non-BMP image.
Tested with files from own HDD, but all of them has got BM header field,
more testing would be welcome.
- Made Jpeg2000 aware of J2K codec. Originally was needed to verify .j2c
files here in the studio, but having support of this codec would be
nice in general.
Currently supports only reading in this codec, writing would still
using jp2 codec.
Diffstat (limited to 'source/blender/imbuf/intern/bmp.c')
-rw-r--r-- | source/blender/imbuf/intern/bmp.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/source/blender/imbuf/intern/bmp.c b/source/blender/imbuf/intern/bmp.c index eb12b219da9..60dd4f65594 100644 --- a/source/blender/imbuf/intern/bmp.c +++ b/source/blender/imbuf/intern/bmp.c @@ -69,16 +69,25 @@ typedef struct BMPHEADER { static int checkbmp(unsigned char *mem) { +#define CHECK_HEADER_FIELD(mem, field) ((mem[0] == field[0]) && (mem[1] == field[0])) + int ret_val = 0; BMPINFOHEADER bmi; unsigned int u; if (mem) { - if ((mem[0] == 'B') && (mem[1] == 'M')) { + if (CHECK_HEADER_FIELD(mem, "BM") || + CHECK_HEADER_FIELD(mem, "BA") || + CHECK_HEADER_FIELD(mem, "CI") || + CHECK_HEADER_FIELD(mem, "CP") || + CHECK_HEADER_FIELD(mem, "IC") || + CHECK_HEADER_FIELD(mem, "PT")) + { /* skip fileheader */ mem += BMP_FILEHEADER_SIZE; } else { + return 0; } /* for systems where an int needs to be 4 bytes aligned */ @@ -97,6 +106,8 @@ static int checkbmp(unsigned char *mem) } return(ret_val); + +#undef CHECK_HEADER_FIELD } int imb_is_a_bmp(unsigned char *buf) |