From 6a877b2e6daae21772768d1973fa801143d312e6 Mon Sep 17 00:00:00 2001 From: Anders Skargren Date: Tue, 16 Feb 2010 21:05:24 +0100 Subject: [PATCH] multipartdemux: improve header mime-type parsing Make the handing of the mime type within the "boundary" a bit less naive. The standard for MIME allows parameters to follow the "type" / "subtype" clause separated from the mime type by ';'. Modifies the multipartdemuxer's header parsing so it doesnt assume the whole line after "content-type:" is the mime type and thus makes it a bit more resilient to finding absurd mime types in the case where parameters are added. Fixes #604711 --- gst/multipart/multipartdemux.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/gst/multipart/multipartdemux.c b/gst/multipart/multipartdemux.c index 1fb62e7..1401c6a 100644 --- a/gst/multipart/multipartdemux.c +++ b/gst/multipart/multipartdemux.c @@ -351,6 +351,18 @@ get_line_end (const guint8 * data, const guint8 * dataend, guint8 ** end, return FALSE; } +static guint +get_mime_len (const guint8 * data, guint maxlen) +{ + guint8 *x; + + x = (guint8 *) data; + while (*x != '\0' && *x != '\r' && *x != '\n' && *x != ';') { + x++; + } + return x - data; +} + static gint multipart_parse_header (GstMultipartDemux * multipart) { @@ -427,8 +439,14 @@ multipart_parse_header (GstMultipartDemux * multipart) } if (len >= 14 && !g_ascii_strncasecmp ("content-type:", (gchar *) pos, 13)) { + guint mime_len; + + /* only take the mime type up to the first ; if any. After ; there can be + * properties that we don't handle yet. */ + mime_len = get_mime_len (pos + 14, len - 14); + g_free (multipart->mime_type); - multipart->mime_type = g_ascii_strdown ((gchar *) pos + 14, len - 14); + multipart->mime_type = g_ascii_strdown ((gchar *) pos + 14, mime_len); } else if (len >= 15 && !g_ascii_strncasecmp ("content-length:", (gchar *) pos, 15)) { multipart->content_length = -- 2.7.4