ext/pango/gsttextoverlay.c: g_markup_escape_text() REALLY doesn't like non-UTF8 input...
authorTim-Philipp Müller <tim@centricular.net>
Wed, 21 Jun 2006 18:39:07 +0000 (18:39 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Wed, 21 Jun 2006 18:39:07 +0000 (18:39 +0000)
Original commit message from CVS:
* ext/pango/gsttextoverlay.c: (gst_text_overlay_make_utf8),
(gst_text_overlay_video_chain):
g_markup_escape_text() REALLY doesn't like non-UTF8 input
and doesn't validate its input either (and neither did
textoverlay it seems). Let's do that then and fix #345206.

ChangeLog
ext/pango/gsttextoverlay.c

index 0121bcb06894753458a42e66e2c9a172c66634a1..8d3efc4324e16f8a55a1bbab9ca2138d7566d523 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-06-21  Tim-Philipp Müller  <tim at centricular dot net>
+
+       * ext/pango/gsttextoverlay.c: (gst_text_overlay_make_utf8),
+       (gst_text_overlay_video_chain):
+         g_markup_escape_text() REALLY doesn't like non-UTF8 input
+         and doesn't validate its input either (and neither did
+         textoverlay it seems). Let's do that then and fix #345206.
+
 2006-06-19  Wim Taymans  <wim@fluendo.com>
 
        * gst/tcp/gstmultifdsink.c: (gst_sync_method_get_type),
index 2caa7674d1b059933f5b5f83cd11fdef43225b45..d604b863944aa26a827567d712adf857b27cf8b4 100644 (file)
@@ -1324,12 +1324,24 @@ gst_text_overlay_video_chain (GstPad * pad, GstBuffer * buffer)
           /* Push the video frame */
           ret = gst_pad_push (overlay->srcpad, buffer);
         } else {
-          const gchar *in_text;
+          gchar *in_text;
           gsize in_size;
 
-          in_text = (const gchar *) GST_BUFFER_DATA (overlay->text_buffer);
+          in_text = (gchar *) GST_BUFFER_DATA (overlay->text_buffer);
           in_size = GST_BUFFER_SIZE (overlay->text_buffer);
 
+          /* g_markup_escape_text() absolutely requires valid UTF8 input, it
+           * might crash otherwise. We don't fall back on GST_SUBTITLE_ENCODING
+           * here on purpose, this is something that needs fixing upstream */
+          if (!g_utf8_validate (in_text, in_size, NULL)) {
+            const gchar *end = NULL;
+
+            GST_WARNING_OBJECT (overlay, "received invalid UTF-8");
+            in_text = g_strndup (in_text, in_size);
+            while (!g_utf8_validate (in_text, in_size, &end) && end)
+              *((gchar *) end) = '*';
+          }
+
           /* Get the string */
           if (overlay->have_pango_markup) {
             text = g_strndup (in_text, in_size);
@@ -1351,6 +1363,9 @@ gst_text_overlay_video_chain (GstPad * pad, GstBuffer * buffer)
             gst_text_overlay_render_text (overlay, " ", 1);
           }
 
+          if (in_text != (gchar *) GST_BUFFER_DATA (overlay->text_buffer))
+            g_free (in_text);
+
           GST_OBJECT_UNLOCK (overlay);
           ret = gst_text_overlay_push_frame (overlay, buffer);
         }