fix: img_load_gif: out-of-bound access

according to imlib2's gif loader, bg should already be transparent black
if bg > cmap->ColorCount
This commit is contained in:
NRK 2021-11-21 09:04:26 +06:00 committed by N-R-K
parent ca7368aa89
commit 470f50f9f8
1 changed files with 7 additions and 4 deletions

11
image.c
View File

@ -203,10 +203,13 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file)
ptr = data = emalloc(sw * sh * sizeof(DATA32)); ptr = data = emalloc(sw * sh * sizeof(DATA32));
cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap; cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap;
r = cmap->Colors[bg].Red; /* if bg > cmap->ColorCount, it is transparent black already */
g = cmap->Colors[bg].Green; if (cmap && bg >= 0 && bg < cmap->ColorCount) {
b = cmap->Colors[bg].Blue; r = cmap->Colors[bg].Red;
bgpixel = 0x00ffffff & (r << 16 | g << 8 | b); g = cmap->Colors[bg].Green;
b = cmap->Colors[bg].Blue;
bgpixel = 0x00ffffff & (r << 16 | g << 8 | b);
}
for (i = 0; i < sh; i++) { for (i = 0; i < sh; i++) {
for (j = 0; j < sw; j++) { for (j = 0; j < sw; j++) {