matroskademux: move the check for subtitle buffer being null terminated before validating UTF-8

https://bugzilla.gnome.org/show_bug.cgi?id=707933
This commit is contained in:
Matej Knopp 2013-09-27 12:53:06 +02:00 committed by Sebastian Dröge
parent d4b4b4e924
commit 40c0586c17

View file

@ -3006,6 +3006,23 @@ gst_matroska_demux_check_subtitle_buffer (GstElement * element,
if (!gst_buffer_get_size (*buf) || !gst_buffer_map (*buf, &map, GST_MAP_READ))
return GST_FLOW_OK;
/* Need \0-terminator at the end */
if (map.data[map.size - 1] != '\0') {
newbuf = gst_buffer_new_and_alloc (map.size + 1);
/* Copy old buffer and add a 0 at the end */
gst_buffer_fill (newbuf, 0, map.data, map.size);
gst_buffer_memset (newbuf, map.size, 0, 1);
gst_buffer_unmap (*buf, &map);
gst_buffer_copy_into (newbuf, *buf,
GST_BUFFER_COPY_TIMESTAMPS | GST_BUFFER_COPY_FLAGS |
GST_BUFFER_COPY_META, 0, -1);
gst_buffer_unref (*buf);
*buf = newbuf;
gst_buffer_map (*buf, &map, GST_MAP_READ);
}
if (!sub_stream->invalid_utf8) {
if (g_utf8_validate ((gchar *) map.data, map.size - 1, NULL)) {
goto next;
@ -3060,22 +3077,6 @@ gst_matroska_demux_check_subtitle_buffer (GstElement * element,
gst_buffer_map (*buf, &map, GST_MAP_READ);
next:
/* Need \0-terminator at the end */
if (map.data[map.size - 1] != '\0') {
newbuf = gst_buffer_new_and_alloc (map.size + 1);
/* Copy old buffer and add a 0 at the end */
gst_buffer_fill (newbuf, 0, map.data, map.size);
gst_buffer_memset (newbuf, map.size, 0, 1);
gst_buffer_unmap (*buf, &map);
gst_buffer_copy_into (newbuf, *buf,
GST_BUFFER_COPY_TIMESTAMPS | GST_BUFFER_COPY_FLAGS |
GST_BUFFER_COPY_META, 0, -1);
gst_buffer_unref (*buf);
*buf = newbuf;
gst_buffer_map (*buf, &map, GST_MAP_READ);
}
if (sub_stream->check_markup) {
/* caps claim markup text, so we need to escape text,