Blame SOURCES/0001-avidemux-Fix-integer-overflow-resulting-in-heap-corr.patch

27715b
From bcfe7befea53869e7836be912ee7efe875877169 Mon Sep 17 00:00:00 2001
27715b
From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
27715b
Date: Wed, 18 May 2022 12:00:48 +0300
27715b
Subject: [PATCH 1/4] avidemux: Fix integer overflow resulting in heap
27715b
 corruption in DIB buffer inversion code
27715b
27715b
Check that width*bpp/8 doesn't overflow a guint and also that
27715b
height*stride fits into the provided buffer without overflowing.
27715b
27715b
Thanks to Adam Doupe for analyzing and reporting the issue.
27715b
27715b
CVE: CVE-2022-1921
27715b
27715b
See https://gstreamer.freedesktop.org/security/sa-2022-0001.html
27715b
27715b
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1224
27715b
27715b
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2608>
27715b
---
27715b
 gst/avi/gstavidemux.c | 17 ++++++++++++++---
27715b
 1 file changed, 14 insertions(+), 3 deletions(-)
27715b
27715b
diff --git a/gst/avi/gstavidemux.c b/gst/avi/gstavidemux.c
27715b
index 25c97da03e..1c87c668d0 100644
27715b
--- a/gst/avi/gstavidemux.c
27715b
+++ b/gst/avi/gstavidemux.c
27715b
@@ -4971,8 +4971,8 @@ swap_line (guint8 * d1, guint8 * d2, guint8 * tmp, gint bytes)
27715b
 static GstBuffer *
27715b
 gst_avi_demux_invert (GstAviStream * stream, GstBuffer * buf)
27715b
 {
27715b
-  gint y, w, h;
27715b
-  gint bpp, stride;
27715b
+  guint y, w, h;
27715b
+  guint bpp, stride;
27715b
   guint8 *tmp = NULL;
27715b
   GstMapInfo map;
27715b
   guint32 fourcc;
27715b
@@ -4999,12 +4999,23 @@ gst_avi_demux_invert (GstAviStream * stream, GstBuffer * buf)
27715b
   h = stream->strf.vids->height;
27715b
   w = stream->strf.vids->width;
27715b
   bpp = stream->strf.vids->bit_cnt ? stream->strf.vids->bit_cnt : 8;
27715b
+
27715b
+  if ((guint64) w * ((guint64) bpp / 8) > G_MAXUINT - 4) {
27715b
+    GST_WARNING ("Width x stride overflows");
27715b
+    return buf;
27715b
+  }
27715b
+
27715b
+  if (w == 0 || h == 0) {
27715b
+    GST_WARNING ("Zero width or height");
27715b
+    return buf;
27715b
+  }
27715b
+
27715b
   stride = GST_ROUND_UP_4 (w * (bpp / 8));
27715b
 
27715b
   buf = gst_buffer_make_writable (buf);
27715b
 
27715b
   gst_buffer_map (buf, &map, GST_MAP_READWRITE);
27715b
-  if (map.size < (stride * h)) {
27715b
+  if (map.size < ((guint64) stride * (guint64) h)) {
27715b
     GST_WARNING ("Buffer is smaller than reported Width x Height x Depth");
27715b
     gst_buffer_unmap (buf, &map);
27715b
     return buf;
27715b
-- 
27715b
2.38.1
27715b