summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Dröge <sebastian@centricular.com>2024-04-25 15:21:20 +0300
committerTim-Philipp Müller <tim@centricular.com>2024-04-29 20:52:19 +0100
commit1ceedfd2c1af3f1ff539d88a120296ffae85e0b2 (patch)
tree6925640976189bdab4636c3eab5229933d97bb1d
parent810876d3d4df506a01fef7b16039a144b59027da (diff)
exiftag: Prevent integer overflows and out of bounds reads when handling undefined tags
Fixes ZDI-CAN-23896 Fixes https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3483 Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6767>
-rw-r--r--subprojects/gst-plugins-base/gst-libs/gst/tag/gstexiftag.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/subprojects/gst-plugins-base/gst-libs/gst/tag/gstexiftag.c b/subprojects/gst-plugins-base/gst-libs/gst/tag/gstexiftag.c
index ed41ccfb46..3b9a2be06b 100644
--- a/subprojects/gst-plugins-base/gst-libs/gst/tag/gstexiftag.c
+++ b/subprojects/gst-plugins-base/gst-libs/gst/tag/gstexiftag.c
@@ -1383,6 +1383,7 @@ parse_exif_undefined_tag (GstExifReader * reader, const GstExifTagMatch * tag,
if (count > 4) {
GstMapInfo info;
+ gsize alloc_size;
if (offset < reader->base_offset) {
GST_WARNING ("Offset is smaller (%u) than base offset (%u)", offset,
@@ -1404,14 +1405,28 @@ parse_exif_undefined_tag (GstExifReader * reader, const GstExifTagMatch * tag,
return;
}
+ if (info.size - real_offset < count) {
+ GST_WARNING ("Invalid size %u for buffer of size %" G_GSIZE_FORMAT
+ ", not adding tag %s", count, info.size, tag->gst_tag);
+ gst_buffer_unmap (reader->buffer, &info);
+ return;
+ }
+
+ if (!g_size_checked_add (&alloc_size, count, 1)) {
+ GST_WARNING ("Invalid size %u for buffer of size %" G_GSIZE_FORMAT
+ ", not adding tag %s", real_offset, info.size, tag->gst_tag);
+ gst_buffer_unmap (reader->buffer, &info);
+ return;
+ }
+
/* +1 because it could be a string without the \0 */
- data = malloc (sizeof (guint8) * count + 1);
+ data = malloc (alloc_size);
memcpy (data, info.data + real_offset, count);
data[count] = 0;
gst_buffer_unmap (reader->buffer, &info);
} else {
- data = malloc (sizeof (guint8) * count + 1);
+ data = malloc (count + 1);
memcpy (data, (guint8 *) offset_as_data, count);
data[count] = 0;
}