dashdemux: added duration format validation

https://bugzilla.gnome.org/show_bug.cgi?id=752336
This commit is contained in:
Florin Apostol 2015-09-29 09:32:02 +01:00 committed by Vincent Penquerc'h
parent f28fad6e83
commit 7dca9fb3f4

View file

@ -947,8 +947,8 @@ gst_mpdparser_get_xml_prop_duration (xmlNode * a_node,
xmlChar *prop_string; xmlChar *prop_string;
gchar *str; gchar *str;
gint ret, len, pos, posT; gint ret, len, pos, posT;
guint years = 0, months = 0, days = 0, hours = 0, minutes = 0, seconds = gint years = -1, months = -1, days = -1, hours = -1, minutes = -1, seconds =
0, decimals = 0, read; -1, decimals = -1, read;
gboolean have_ms = FALSE; gboolean have_ms = FALSE;
gboolean exists = FALSE; gboolean exists = FALSE;
@ -986,12 +986,24 @@ gst_mpdparser_get_xml_prop_duration (xmlNode * a_node,
} }
switch (str[pos]) { switch (str[pos]) {
case 'Y': case 'Y':
if (years != -1 || months != -1 || days != -1) {
GST_WARNING ("year, month or day was already set");
goto error;
}
years = read; years = read;
break; break;
case 'M': case 'M':
if (months != -1 || days != -1) {
GST_WARNING ("month or day was already set");
goto error;
}
months = read; months = read;
break; break;
case 'D': case 'D':
if (days != -1) {
GST_WARNING ("day was already set");
goto error;
}
days = read; days = read;
break; break;
default: default:
@ -1003,9 +1015,17 @@ gst_mpdparser_get_xml_prop_duration (xmlNode * a_node,
str += (pos + 1); str += (pos + 1);
posT -= (pos + 1); posT -= (pos + 1);
} while (posT > 0); } while (posT > 0);
GST_TRACE ("Y:M:D=%u:%u:%u", years, months, days);
} }
if (years == -1)
years = 0;
if (months == -1)
months = 0;
if (days == -1)
days = 0;
GST_TRACE ("Y:M:D=%d:%d:%d", years, months, days);
/* read "T" for time (if present) */ /* read "T" for time (if present) */
/* here T is at pos == 0 */ /* here T is at pos == 0 */
str++; str++;
@ -1024,9 +1044,17 @@ gst_mpdparser_get_xml_prop_duration (xmlNode * a_node,
} }
switch (str[pos]) { switch (str[pos]) {
case 'H': case 'H':
if (hours != -1 || minutes != -1 || seconds != -1) {
GST_WARNING ("hour, minute or second was already set");
goto error;
}
hours = read; hours = read;
break; break;
case 'M': case 'M':
if (minutes != -1 || seconds != -1) {
GST_WARNING ("minute or second was already set");
goto error;
}
minutes = read; minutes = read;
break; break;
case 'S': case 'S':
@ -1036,6 +1064,10 @@ gst_mpdparser_get_xml_prop_duration (xmlNode * a_node,
GST_TRACE ("decimal number %u (%d digits) -> %d ms", read, pos, GST_TRACE ("decimal number %u (%d digits) -> %d ms", read, pos,
decimals); decimals);
} else { } else {
if (seconds != -1) {
GST_WARNING ("second was already set");
goto error;
}
/* no decimals */ /* no decimals */
seconds = read; seconds = read;
} }
@ -1043,6 +1075,10 @@ gst_mpdparser_get_xml_prop_duration (xmlNode * a_node,
case '.': case '.':
case ',': case ',':
/* we have read the integer part of a decimal number in seconds */ /* we have read the integer part of a decimal number in seconds */
if (seconds != -1) {
GST_WARNING ("second was already set");
goto error;
}
seconds = read; seconds = read;
have_ms = TRUE; have_ms = TRUE;
break; break;
@ -1055,10 +1091,18 @@ gst_mpdparser_get_xml_prop_duration (xmlNode * a_node,
str += pos + 1; str += pos + 1;
len -= (pos + 1); len -= (pos + 1);
} while (len > 0); } while (len > 0);
GST_TRACE ("H:M:S.MS=%u:%u:%u.%03u", hours, minutes, seconds, decimals);
} }
if (hours == -1)
hours = 0;
if (minutes == -1)
minutes = 0;
if (seconds == -1)
seconds = 0;
if (decimals == -1)
decimals = 0;
GST_TRACE ("H:M:S.MS=%d:%d:%d.%03d", hours, minutes, seconds, decimals);
xmlFree (prop_string); xmlFree (prop_string);
exists = TRUE; exists = TRUE;
*property_value = *property_value =