basetextoverlay: Fix segfault when overlay outside the frame
authorLuis de Bethencourt <luis.bg@samsung.com>
Fri, 10 Oct 2014 04:35:19 +0000 (10:05 +0530)
committerLuis de Bethencourt <luis.bg@samsung.com>
Sat, 11 Oct 2014 18:06:03 +0000 (19:06 +0100)
When the textoverlay is set outside the video frame by deltax or deltay the
calculation segfaults, but it is also  unnecessary since it doesn't need to be
displayed. So we should clip the text.

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

ext/pango/gstbasetextoverlay.c

index 488f1822cb35d533e2cd30f30e72ecd0b4c6af5a..229b2aefb1d83ba4199f9fa648eab0dd8970d3e9 100644 (file)
@@ -1364,34 +1364,42 @@ gst_base_text_overlay_get_pos (GstBaseTextOverlay * overlay,
       *xpos = 0;
   }
   *xpos += overlay->deltax;
-
-  if (overlay->use_vertical_render)
-    valign = GST_BASE_TEXT_OVERLAY_VALIGN_TOP;
-  else
-    valign = overlay->valign;
-
-  switch (valign) {
-    case GST_BASE_TEXT_OVERLAY_VALIGN_BOTTOM:
-      *ypos = overlay->height - height - overlay->ypad;
-      break;
-    case GST_BASE_TEXT_OVERLAY_VALIGN_BASELINE:
-      *ypos = overlay->height - (height + overlay->ypad);
-      break;
-    case GST_BASE_TEXT_OVERLAY_VALIGN_TOP:
-      *ypos = overlay->ypad;
-      break;
-    case GST_BASE_TEXT_OVERLAY_VALIGN_POS:
-      *ypos = (gint) (overlay->height * overlay->ypos) - height / 2;
-      *ypos = CLAMP (*ypos, 0, overlay->height - height);
-      break;
-    case GST_BASE_TEXT_OVERLAY_VALIGN_CENTER:
-      *ypos = (overlay->height - height) / 2;
-      break;
-    default:
-      *ypos = overlay->ypad;
-      break;
+  if (*xpos > overlay->width) {
+    /* Clip text if out of frame */
+    overlay->silent = TRUE;
+  } else {
+    if (overlay->use_vertical_render)
+      valign = GST_BASE_TEXT_OVERLAY_VALIGN_TOP;
+    else
+      valign = overlay->valign;
+
+    switch (valign) {
+      case GST_BASE_TEXT_OVERLAY_VALIGN_BOTTOM:
+        *ypos = overlay->height - height - overlay->ypad;
+        break;
+      case GST_BASE_TEXT_OVERLAY_VALIGN_BASELINE:
+        *ypos = overlay->height - (height + overlay->ypad);
+        break;
+      case GST_BASE_TEXT_OVERLAY_VALIGN_TOP:
+        *ypos = overlay->ypad;
+        break;
+      case GST_BASE_TEXT_OVERLAY_VALIGN_POS:
+        *ypos = (gint) (overlay->height * overlay->ypos) - height / 2;
+        *ypos = CLAMP (*ypos, 0, overlay->height - height);
+        break;
+      case GST_BASE_TEXT_OVERLAY_VALIGN_CENTER:
+        *ypos = (overlay->height - height) / 2;
+        break;
+      default:
+        *ypos = overlay->ypad;
+        break;
+    }
+    *ypos += overlay->deltay;
+    if (*ypos > overlay->height) {
+      /* Clip text if out of frame */
+      overlay->silent = TRUE;
+    }
   }
-  *ypos += overlay->deltay;
 }
 
 static inline void