matroska-mux: Fix sparse stream crash
authorJan Schmidt <jan@centricular.com>
Tue, 27 Oct 2020 12:43:49 +0000 (23:43 +1100)
committerJan Schmidt <jan@centricular.com>
Tue, 27 Oct 2020 14:55:06 +0000 (01:55 +1100)
https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/656
introduced an invalid memory access when debug is enabled, by casting
the wrong pointer to a GstCollectPad. Fixing that showed the original
change was incorrect and leads to an infinite loop in the
testsuite. This patch fixes both problems.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/merge_requests/788>

gst/matroska/matroska-mux.c

index 85cb1f2..3cb9bae 100644 (file)
@@ -2255,8 +2255,6 @@ refuse_caps:
 static gboolean
 gst_matroska_mux_subtitle_pad_setcaps (GstPad * pad, GstCaps * caps)
 {
-  GstCollectData *data = (GstCollectData *) (pad);
-
   /* There is now (at least) one such alement (kateenc), and I'm going
      to handle it here and claim it works when it can be piped back
      through GStreamer and VLC */
@@ -2265,6 +2263,7 @@ gst_matroska_mux_subtitle_pad_setcaps (GstPad * pad, GstCaps * caps)
   GstMatroskaTrackSubtitleContext *scontext;
   GstMatroskaMux *mux;
   GstMatroskaPad *collect_pad;
+  GstCollectData *data;
   const gchar *mimetype;
   GstStructure *structure;
   const GValue *value = NULL;
@@ -2293,6 +2292,8 @@ gst_matroska_mux_subtitle_pad_setcaps (GstPad * pad, GstCaps * caps)
   /* find context */
   collect_pad = (GstMatroskaPad *) gst_pad_get_element_private (pad);
   g_assert (collect_pad);
+  data = (GstCollectData *) (collect_pad);
+
   context = collect_pad->track;
   g_assert (context);
   g_assert (context->type == GST_MATROSKA_TRACK_TYPE_SUBTITLE);
@@ -2373,10 +2374,8 @@ gst_matroska_mux_subtitle_pad_setcaps (GstPad * pad, GstCaps * caps)
   GST_COLLECT_PADS_STREAM_LOCK (mux->collect);
   GST_COLLECT_PADS_STATE_UNSET (data, GST_COLLECT_PADS_STATE_LOCKED);
   gst_collect_pads_set_waiting (mux->collect, data, FALSE);
-  GST_COLLECT_PADS_STATE_SET (data, GST_COLLECT_PADS_STATE_LOCKED);
   GST_COLLECT_PADS_STREAM_UNLOCK (mux->collect);
 
-
 exit:
 
   return ret;