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
This commit is contained in:
Anders Skargren 2010-02-16 21:05:24 +01:00 committed by Wim Taymans
parent a0b651bf5b
commit 6a877b2e6d

View file

@ -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 =