diff options
author | Philip Jägenstedt <philipj@opera.com> | 2010-05-12 13:16:28 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2010-05-19 20:33:38 +0200 |
commit | c712d2879655ecf0e503e06cd32eb058ef1af047 (patch) | |
tree | e235a2b7a007318a2c7f6bcfa17f6409545c5e32 | |
parent | d14697112864f385e0a341cde6533f9e22d04c36 (diff) |
ebml: Validate 7-bit ASCII in gst_ebml_read_ascii
This was triggering an UTF-8 assertion in gst_caps_set_simple for
corrupt files with garbage as codec id. Test case:
gstreamer_error_trying_to_set_invalid_utf8_as_codec_id.webm
Old gst_ebml_read_ascii renamed to gst_ebml_read_string, also used by
gst_ebml_read_utf8. Unlike for UTF-8, failure to validate is an error,
as gst_ebml_read_ascii is used for reading doctype and codec id and we
might just as well give up early in those cases.
-rw-r--r-- | gst/matroska/ebml-read.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/gst/matroska/ebml-read.c b/gst/matroska/ebml-read.c index 5a8eea5d9..e53027afa 100644 --- a/gst/matroska/ebml-read.c +++ b/gst/matroska/ebml-read.c @@ -776,11 +776,11 @@ gst_ebml_read_float (GstEbmlRead * ebml, guint32 * id, gdouble * num) } /* - * Read the next element as an ASCII string. + * Read the next element as a C string. */ -GstFlowReturn -gst_ebml_read_ascii (GstEbmlRead * ebml, guint32 * id, gchar ** str) +static GstFlowReturn +gst_ebml_read_string (GstEbmlRead * ebml, guint32 * id, gchar ** str) { guint8 *data; guint size; @@ -798,6 +798,36 @@ gst_ebml_read_ascii (GstEbmlRead * ebml, guint32 * id, gchar ** str) } /* + * Read the next element as an ASCII string. + */ + +GstFlowReturn +gst_ebml_read_ascii (GstEbmlRead * ebml, guint32 * id, gchar ** str) +{ + GstFlowReturn ret; + gchar *iter; + +#ifndef GST_DISABLE_GST_DEBUG + guint64 oldoff = ebml->offset; +#endif + + ret = gst_ebml_read_string (ebml, id, str); + if (ret != GST_FLOW_OK) + return ret; + + for (iter = *str; *iter != '\0'; iter++) { + if (G_UNLIKELY (*iter & 0x80)) { + GST_ERROR_OBJECT (ebml, + "Invalid ASCII string at offset %" G_GUINT64_FORMAT, oldoff); + g_free (*str); + return GST_FLOW_ERROR; + } + } + + return ret; +} + +/* * Read the next element as a UTF-8 string. */ @@ -810,7 +840,7 @@ gst_ebml_read_utf8 (GstEbmlRead * ebml, guint32 * id, gchar ** str) guint64 oldoff = ebml->offset; #endif - ret = gst_ebml_read_ascii (ebml, id, str); + ret = gst_ebml_read_string (ebml, id, str); if (ret != GST_FLOW_OK) return ret; |