oggdemux: fix potential crash in SEEKING query handler
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 13 May 2012 22:11:20 +0000 (23:11 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Sun, 13 May 2012 22:23:03 +0000 (23:23 +0100)
Take chain lock when accessing chains. Fall back gracefully
when there's no current chain Hopefully fixes crash when
seeking in Jamendo or Magnatune streams in Amarok.

https://bugzilla.gnome.org/show_bug.cgi?id=675609

ext/ogg/gstoggdemux.c

index 0c1a9bb..cb8c2f7 100644 (file)
@@ -301,11 +301,23 @@ gst_ogg_pad_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
         gboolean seekable = FALSE;
         gint64 stop = -1;
 
+        GST_CHAIN_LOCK (ogg);
         if (ogg->pullmode) {
           seekable = TRUE;
           stop = ogg->total_time;
         } else if (ogg->push_disable_seeking) {
           seekable = FALSE;
+        } else if (ogg->current_chain == NULL) {
+          GstQuery *squery;
+
+          /* assume we can seek if upstream is seekable in BYTES format */
+          GST_LOG_OBJECT (ogg, "no current chain, check upstream seekability");
+          squery = gst_query_new_seeking (GST_FORMAT_BYTES);
+          if (gst_pad_peer_query (ogg->sinkpad, squery))
+            gst_query_parse_seeking (squery, NULL, &seekable, NULL, NULL);
+          else
+            seekable = FALSE;
+          gst_query_unref (squery);
         } else if (ogg->current_chain->streams->len) {
           gint i;
 
@@ -334,6 +346,7 @@ gst_ogg_pad_src_query (GstPad * pad, GstObject * parent, GstQuery * query)
         }
 
         gst_query_set_seeking (query, GST_FORMAT_TIME, seekable, 0, stop);
+        GST_CHAIN_UNLOCK (ogg);
       } else {
         res = FALSE;
       }