2ab6fb
From 24267889a717e1e799037a0f1841d5416eb56e75 Mon Sep 17 00:00:00 2001
2ab6fb
From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= <sebastian@centricular.com>
2ab6fb
Date: Mon, 30 May 2022 10:15:37 +0300
2ab6fb
Subject: [PATCH 3/4] qtdemux: Fix integer overflows in zlib decompression code
2ab6fb
2ab6fb
Various variables were of smaller types than needed and there were no
2ab6fb
checks for any overflows when doing additions on the sizes. This is all
2ab6fb
checked now.
2ab6fb
2ab6fb
In addition the size of the decompressed data is limited to 200MB now as
2ab6fb
any larger sizes are likely pathological and we can avoid out of memory
2ab6fb
situations in many cases like this.
2ab6fb
2ab6fb
Also fix a bug where the available output size on the next iteration in
2ab6fb
the zlib decompression code was provided too large and could
2ab6fb
potentially lead to out of bound writes.
2ab6fb
2ab6fb
Thanks to Adam Doupe for analyzing and reporting the issue.
2ab6fb
2ab6fb
CVE: tbd
2ab6fb
2ab6fb
https://gstreamer.freedesktop.org/security/sa-2022-0003.html
2ab6fb
2ab6fb
Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/1225
2ab6fb
2ab6fb
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/2610>
2ab6fb
---
2ab6fb
 gst/isomp4/qtdemux.c | 8 +++++++-
2ab6fb
 1 file changed, 7 insertions(+), 1 deletion(-)
2ab6fb
2ab6fb
diff --git a/gst/isomp4/qtdemux.c b/gst/isomp4/qtdemux.c
2ab6fb
index 182d0bc06f..a9cbbd4cd3 100644
2ab6fb
--- a/gst/isomp4/qtdemux.c
2ab6fb
+++ b/gst/isomp4/qtdemux.c
2ab6fb
@@ -7611,10 +7611,16 @@ qtdemux_inflate (void *z_buffer, guint z_length, guint * length)
2ab6fb
       break;
2ab6fb
     }
2ab6fb
 
2ab6fb
+    if (*length > G_MAXUINT - 4096 || *length > QTDEMUX_MAX_SAMPLE_INDEX_SIZE) {
2ab6fb
+      GST_WARNING ("too big decompressed data");
2ab6fb
+      ret = Z_MEM_ERROR;
2ab6fb
+      break;
2ab6fb
+    }
2ab6fb
+
2ab6fb
     *length += 4096;
2ab6fb
     buffer = (guint8 *) g_realloc (buffer, *length);
2ab6fb
     z.next_out = (Bytef *) (buffer + z.total_out);
2ab6fb
-    z.avail_out += 4096;
2ab6fb
+    z.avail_out += *length - z.total_out;
2ab6fb
   } while (z.avail_in > 0);
2ab6fb
 
2ab6fb
   if (ret != Z_STREAM_END) {
2ab6fb
-- 
2ab6fb
2.38.1
2ab6fb