From 8cdf3858127bbe1a23bd68546ddcb5b350a03904 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 15 Aug 2016 21:14:10 +0100 Subject: do not stop bitmap decode on first out of range colour table index This changes behaviour to ignore image indices outside the range of entries in the colour table. This allows a greater number of "real world" bitmaps to be decoded which often have such bad palette references within them. --- src/libnsbmp.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libnsbmp.c b/src/libnsbmp.c index 1b28167..b4747f6 100644 --- a/src/libnsbmp.c +++ b/src/libnsbmp.c @@ -708,11 +708,14 @@ static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes) cur_byte = *data++; } idx = (cur_byte >> bit_shifts[bit++]) & bit_mask; - if (idx >= bmp->colours) - return BMP_DATA_ERROR; - scanline[x] = bmp->colour_table[idx]; - if ((bmp->limited_trans) && (scanline[x] == bmp->transparent_index)) - scanline[x] = bmp->trans_colour; + if (idx < bmp->colours) { + /* ensure colour table index is in bounds */ + scanline[x] = bmp->colour_table[idx]; + if ((bmp->limited_trans) && + (scanline[x] == bmp->transparent_index)) { + scanline[x] = bmp->trans_colour; + } + } } } *start = data; -- cgit v1.2.3