82b134
From 6976bdc8ee9dd2c2954f91066f7b0f643769a379 Mon Sep 17 00:00:00 2001
82b134
From: Robert Ancell <robert.ancell@canonical.com>
82b134
Date: Thu, 3 Jun 2021 11:05:56 +1200
82b134
Subject: [PATCH] gif: Check for overflow when compositing or clearing frames.
82b134
82b134
Fixes: #190
82b134
82b134
Similar to fix in 086e8adf4cc352cd11572f96066b001b545f354e
82b134
---
82b134
 gdk-pixbuf/io-gif-animation.c | 21 +++++++++++++--------
82b134
 1 file changed, 13 insertions(+), 8 deletions(-)
82b134
82b134
diff --git a/gdk-pixbuf/io-gif-animation.c b/gdk-pixbuf/io-gif-animation.c
82b134
index 8335cdd76..71d9265e6 100644
82b134
--- a/gdk-pixbuf/io-gif-animation.c
82b134
+++ b/gdk-pixbuf/io-gif-animation.c
82b134
@@ -369,7 +369,7 @@ composite_frame (GdkPixbufGifAnim *anim, GdkPixbufFrame *frame)
82b134
         for (i = 0; i < n_indexes; i++) {
82b134
                 guint8 index = index_buffer[i];
82b134
                 guint x, y;
82b134
-                int offset;
82b134
+                gsize offset;
82b134
 
82b134
                 if (index == frame->transparent_index)
82b134
                         continue;
82b134
@@ -379,11 +379,13 @@ composite_frame (GdkPixbufGifAnim *anim, GdkPixbufFrame *frame)
82b134
                 if (x >= anim->width || y >= anim->height)
82b134
                         continue;
82b134
 
82b134
-                offset = y * gdk_pixbuf_get_rowstride (anim->last_frame_data) + x * 4;
82b134
-                pixels[offset + 0] = frame->color_map[index * 3 + 0];
82b134
-                pixels[offset + 1] = frame->color_map[index * 3 + 1];
82b134
-                pixels[offset + 2] = frame->color_map[index * 3 + 2];
82b134
-                pixels[offset + 3] = 255;
82b134
+                if (g_size_checked_mul (&offset, gdk_pixbuf_get_rowstride (anim->last_frame_data), y) &&
82b134
+                    g_size_checked_add (&offset, offset, x * 4)) {
82b134
+                        pixels[offset + 0] = frame->color_map[index * 3 + 0];
82b134
+                        pixels[offset + 1] = frame->color_map[index * 3 + 1];
82b134
+                        pixels[offset + 2] = frame->color_map[index * 3 + 2];
82b134
+                        pixels[offset + 3] = 255;
82b134
+                }
82b134
         }
82b134
 
82b134
 out:
82b134
@@ -448,8 +450,11 @@ gdk_pixbuf_gif_anim_iter_get_pixbuf (GdkPixbufAnimationIter *anim_iter)
82b134
                         x_end = MIN (anim->last_frame->x_offset + anim->last_frame->width, anim->width);
82b134
                         y_end = MIN (anim->last_frame->y_offset + anim->last_frame->height, anim->height);
82b134
                         for (y = anim->last_frame->y_offset; y < y_end; y++) {
82b134
-                                guchar *line = pixels + y * gdk_pixbuf_get_rowstride (anim->last_frame_data) + anim->last_frame->x_offset * 4;
82b134
-                                memset (line, 0, (x_end - anim->last_frame->x_offset) * 4);
82b134
+                                gsize offset;
82b134
+                                if (g_size_checked_mul (&offset, gdk_pixbuf_get_rowstride (anim->last_frame_data), y) &&
82b134
+                                    g_size_checked_add (&offset, offset, anim->last_frame->x_offset * 4)) {
82b134
+                                         memset (pixels + offset, 0, (x_end - anim->last_frame->x_offset) * 4);
82b134
+                                }
82b134
                         }
82b134
                         break;
82b134
                 case GDK_PIXBUF_FRAME_REVERT:
82b134
-- 
82b134
GitLab
82b134