dash_mpd: restrict segment template format strings to %0[0-9]*d as per spec

https://bugzilla.gnome.org/show_bug.cgi?id=751735
This commit is contained in:
Vincent Penquerc'h 2015-10-29 12:04:31 +00:00
parent 4eea6c3833
commit 7443f35249
2 changed files with 14 additions and 18 deletions

View file

@ -2968,23 +2968,19 @@ validate_format (const gchar * format)
return FALSE; return FALSE;
p++; p++;
/* the spec mandates a format like %0[width]d /* the spec mandates a format like %0[width]d */
But we also accept %d, because it doesn't hurt us /* Following the %, we must have a 0 */
*/ if (p[0] != '0')
/* Following the %, if we have a number, it must start with 0 */
if (g_ascii_isdigit (p[0]) && p[0] != '0')
return FALSE; return FALSE;
/* Following the % must be a number, or any of d, x or u. /* Following the % must be a number starting with 0
* x and u are not part of the spec, but don't hurt us
*/ */
while (g_ascii_isdigit (*p)) while (g_ascii_isdigit (*p))
p++; p++;
/* After any 0 and alphanumeric values, there must be /* After any 0 and alphanumeric values, there must be a d.
* an d, x or u.
*/ */
if (p[0] != 'd' && p[0] != 'x' && p[0] != 'u') if (p[0] != 'd')
return FALSE; return FALSE;
p++; p++;
@ -3020,10 +3016,10 @@ promote_format_to_uint64 (const gchar * format)
p++; p++;
} }
/* After any 0 and alphanumeric values, there must be /* After any 0 and alphanumeric values, there must be a d.
* an d, x or u. Otherwise validation would have failed * Otherwise validation would have failed
*/ */
g_assert (p[0] == 'd' || p[0] == 'x' || p[0] == 'u'); g_assert (p[0] == 'd');
promoted_format = promoted_format =
g_strdup_printf ("%.*s" G_GINT64_MODIFIER "%s", (gint) (p - format), g_strdup_printf ("%.*s" G_GINT64_MODIFIER "%s", (gint) (p - format),

View file

@ -2488,7 +2488,7 @@ GST_START_TEST (dash_mpdparser_template_parsing)
{"TestMedia$Bandwidth$$$test", "TestMedia2500$test"}, /* Bandwidth identifier */ {"TestMedia$Bandwidth$$$test", "TestMedia2500$test"}, /* Bandwidth identifier */
{"TestMedia$Time$", "TestMedia100"}, /* Time identifier */ {"TestMedia$Time$", "TestMedia100"}, /* Time identifier */
{"TestMedia$Time", NULL}, /* Identifier not finished with $ */ {"TestMedia$Time", NULL}, /* Identifier not finished with $ */
{"Time$Time%d$", "Time100"}, /* usage of %d (no width) */ {"Time$Time%d$", NULL}, /* usage of %d (no width) */
{"Time$Time%0d$", "Time100"}, /* usage of format smaller than number of digits */ {"Time$Time%0d$", "Time100"}, /* usage of format smaller than number of digits */
{"Time$Time%01d$", "Time100"}, /* usage of format smaller than number of digits */ {"Time$Time%01d$", "Time100"}, /* usage of format smaller than number of digits */
{"Time$Time%05d$", "Time00100"}, /* usage of format bigger than number of digits */ {"Time$Time%05d$", "Time00100"}, /* usage of format bigger than number of digits */
@ -2503,10 +2503,10 @@ GST_START_TEST (dash_mpdparser_template_parsing)
{"$Bandwidth1$", NULL}, /* incorrect identifier */ {"$Bandwidth1$", NULL}, /* incorrect identifier */
{"$Number1$", NULL}, /* incorrect identifier */ {"$Number1$", NULL}, /* incorrect identifier */
{"$RepresentationID%01d$", NULL}, /* incorrect format: RepresentationID does not support formatting */ {"$RepresentationID%01d$", NULL}, /* incorrect format: RepresentationID does not support formatting */
{"Time$Time%05u$", "Time00100"}, /* %u format */ {"Time$Time%05u$", NULL}, /* %u format */
{"Time$Time%05x$", "Time00064"}, /* %x format */ {"Time$Time%05x$", NULL}, /* %x format */
{"Time$Time%05utest$", "Time00100test"}, /* %u format followed by text */ {"Time$Time%05utest$", NULL}, /* %u format followed by text */
{"Time$Time%05xtest$", "Time00064test"}, /* %x format followed by text */ {"Time$Time%05xtest$", NULL}, /* %x format followed by text */
{"Time$Time%05xtest%$", NULL}, /* second % character in format */ {"Time$Time%05xtest%$", NULL}, /* second % character in format */
}; };