git » pipewire.git » main » tree

[main] / 0003-gst-Fix-sanitization-of-non-writable-caps.patch

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Robert Mader <robert.mader@collabora.com>
Date: Thu, 7 Mar 2024 06:55:09 +0100
Subject: [PATCH] gst: Fix sanitization of non-writable caps

`gst_caps_make_writable()` may create a copy which we have to keep
using afterwards. The return value was meant to be used for that,
but was promptly forgotten for the initial user.
Avoid such errors in the future by using an in-out parameter instead.

While on it, add a type check and remove a check for an impossible
condition.

Fixes: 8a271a87b ("gst: Sanitize caps before translating")
---
 src/gst/gstpipewireformat.c | 11 ++++++-----
 src/gst/gstpipewireformat.h |  2 +-
 src/gst/gstpipewiresrc.c    |  2 +-
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/src/gst/gstpipewireformat.c b/src/gst/gstpipewireformat.c
index 6830de234a8d..a0f64747697c 100644
--- a/src/gst/gstpipewireformat.c
+++ b/src/gst/gstpipewireformat.c
@@ -1209,10 +1209,11 @@ filter_dmabuf_caps (GstCapsFeatures *features,
   return TRUE;
 }
 
-GstCaps *
-gst_caps_sanitize (GstCaps *caps)
+void
+gst_caps_sanitize (GstCaps **caps)
 {
-  caps = gst_caps_make_writable (caps);
-  gst_caps_filter_and_map_in_place (caps, filter_dmabuf_caps, NULL);
-  return caps;
+  g_return_if_fail (GST_IS_CAPS (*caps));
+
+  *caps = gst_caps_make_writable (*caps);
+  gst_caps_filter_and_map_in_place (*caps, filter_dmabuf_caps, NULL);
 }
diff --git a/src/gst/gstpipewireformat.h b/src/gst/gstpipewireformat.h
index ca76b70c2f06..1c3a239baeaf 100644
--- a/src/gst/gstpipewireformat.h
+++ b/src/gst/gstpipewireformat.h
@@ -15,7 +15,7 @@ GPtrArray *      gst_caps_to_format_all  (GstCaps *caps);
 
 GstCaps *        gst_caps_from_format    (const struct spa_pod *format);
 
-GstCaps *        gst_caps_sanitize       (GstCaps *caps);
+void             gst_caps_sanitize       (GstCaps **caps);
 
 G_END_DECLS
 
diff --git a/src/gst/gstpipewiresrc.c b/src/gst/gstpipewiresrc.c
index a9ef7d1b2430..5e518884f2f8 100644
--- a/src/gst/gstpipewiresrc.c
+++ b/src/gst/gstpipewiresrc.c
@@ -849,7 +849,7 @@ gst_pipewire_src_negotiate (GstBaseSrc * basesrc)
   }
 
   GST_DEBUG_OBJECT (basesrc, "have common caps: %" GST_PTR_FORMAT, possible_caps);
-  gst_caps_sanitize (possible_caps);
+  gst_caps_sanitize (&possible_caps);
 
   if (gst_caps_is_empty (possible_caps))
     goto no_common_caps;