summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-08-15 21:14:10 +0100
committerVincent Sanders <vince@kyllikki.org>2016-08-15 21:14:10 +0100
commit8cdf3858127bbe1a23bd68546ddcb5b350a03904 (patch)
tree6af6bda7fd431cd0e01328137e18d42de6b06b51
parent81e725731b2294d6d6dc41ee1c0df43302dbb1b7 (diff)
downloadlibnsbmp-8cdf3858127bbe1a23bd68546ddcb5b350a03904.tar.gz
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.
-rw-r--r--src/libnsbmp.c13
1 files 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;