[totem] backend: Sanity check sub/lang indexes



commit 622c214841c0937e0aab5befd1c006cdab12fe4c
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Mar 6 17:15:45 2013 +0100

    backend: Sanity check sub/lang indexes
    
    Check that the subtitle or language requested to
    bacon_video_widget_set_language() or
    bacon_video_widget_set_subtitle() is valid

 src/backend/bacon-video-widget.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/src/backend/bacon-video-widget.c b/src/backend/bacon-video-widget.c
index 2be39e5..080bd09 100644
--- a/src/backend/bacon-video-widget.c
+++ b/src/backend/bacon-video-widget.c
@@ -2748,6 +2748,20 @@ bacon_video_widget_get_subtitle (BaconVideoWidget * bvw)
   return subtitle;
 }
 
+static gboolean
+sublang_is_valid (int sublang,
+                 int n_sublang)
+{
+  if (sublang == -1 ||
+      sublang == -2)
+    return TRUE;
+  if (sublang < 0)
+    return FALSE;
+  if (sublang >= n_sublang)
+    return FALSE;
+  return TRUE;
+}
+
 /**
  * bacon_video_widget_set_subtitle:
  * @bvw: a #BaconVideoWidget
@@ -2761,11 +2775,14 @@ bacon_video_widget_set_subtitle (BaconVideoWidget * bvw, int subtitle)
 {
   GstTagList *tags;
   gint flags;
+  gint n_text;
 
   g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
   g_return_if_fail (bvw->priv->play != NULL);
 
-  g_object_get (bvw->priv->play, "flags", &flags, NULL);
+  g_object_get (bvw->priv->play, "flags", &flags, "n-text", &n_text, NULL);
+
+  g_return_if_fail (sublang_is_valid (subtitle, n_text));
 
   if (subtitle == -2) {
     flags &= ~GST_PLAY_FLAG_TEXT;
@@ -2984,10 +3001,15 @@ void
 bacon_video_widget_set_language (BaconVideoWidget * bvw, int language)
 {
   GstTagList *tags;
+  int n_lang;
 
   g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
   g_return_if_fail (bvw->priv->play != NULL);
 
+  g_object_get (bvw->priv->play, "n-audio", &n_lang, NULL);
+
+  g_return_if_fail (sublang_is_valid (language, n_lang));
+
   if (language == -1)
     language = 0;
   else if (language == -2)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]