aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNRK <nrk@disroot.org>2021-11-21 09:04:26 +0600
committerN-R-K <79544946+N-R-K@users.noreply.github.com>2021-11-26 15:36:05 +0600
commit470f50f9f885987e39b335547e2a3809d6b8056f (patch)
treef2ed48013b445e0458eb54aa10a3629a0f7f24e4
parentca7368aa8960ee6b7094b997dcc71ffb5b1e310f (diff)
fix: img_load_gif: out-of-bound access
according to imlib2's gif loader, bg should already be transparent black if bg > cmap->ColorCount
-rw-r--r--image.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/image.c b/image.c
index 980bf1a..eaa35da 100644
--- a/image.c
+++ b/image.c
@@ -203,10 +203,13 @@ static bool img_load_gif(img_t *img, const fileinfo_t *file)
ptr = data = emalloc(sw * sh * sizeof(DATA32));
cmap = gif->Image.ColorMap ? gif->Image.ColorMap : gif->SColorMap;
- r = cmap->Colors[bg].Red;
- g = cmap->Colors[bg].Green;
- b = cmap->Colors[bg].Blue;
- bgpixel = 0x00ffffff & (r << 16 | g << 8 | b);
+ /* if bg > cmap->ColorCount, it is transparent black already */
+ if (cmap && bg >= 0 && bg < cmap->ColorCount) {
+ r = cmap->Colors[bg].Red;
+ g = cmap->Colors[bg].Green;
+ b = cmap->Colors[bg].Blue;
+ bgpixel = 0x00ffffff & (r << 16 | g << 8 | b);
+ }
for (i = 0; i < sh; i++) {
for (j = 0; j < sw; j++) {