diff --git a/ext/dash/gstmpdparser.c b/ext/dash/gstmpdparser.c index 15d33eff66..059f1eaa66 100644 --- a/ext/dash/gstmpdparser.c +++ b/ext/dash/gstmpdparser.c @@ -4195,6 +4195,10 @@ gst_mpd_client_setup_media_presentation (GstMpdClient * client, } duration = next_period_node->start * GST_MSECOND - start; } else if (period_node->duration != -1) { + if (period_node->duration <= 0) { + /* Invalid MPD file: duration would be negative or zero */ + goto syntax_error; + } duration = period_node->duration * GST_MSECOND; } else if (client->mpd_node->type == GST_MPD_FILE_TYPE_DYNAMIC) { /* might be a live file, ignore unspecified duration */ diff --git a/tests/check/elements/dash_mpd.c b/tests/check/elements/dash_mpd.c index 855a0f5244..f7af6d40c7 100644 --- a/tests/check/elements/dash_mpd.c +++ b/tests/check/elements/dash_mpd.c @@ -4490,6 +4490,40 @@ GST_START_TEST (dash_mpdparser_rfc1738_strings) GST_END_TEST; +/* + * Test negative period duration + */ +GST_START_TEST (dash_mpdparser_negative_period_duration) +{ + const gchar *xml = + "" + "" + " " + " "; + + gboolean ret; + GstMpdClient *mpdclient = gst_mpd_client_new (); + + ret = gst_mpd_parse (mpdclient, xml, (gint) strlen (xml)); + assert_equals_int (ret, TRUE); + + /* process the xml data + * should fail due to negative duration of Period0 + */ + ret = gst_mpd_client_setup_media_presentation (mpdclient, GST_CLOCK_TIME_NONE, + -1, NULL); + assert_equals_int (ret, FALSE); + + gst_mpd_client_free (mpdclient); +} + +GST_END_TEST; + /* * create a test suite containing all dash testcases */ @@ -4648,6 +4682,7 @@ dash_suite (void) dash_mpdparser_wrong_period_duration_inferred_from_next_period); tcase_add_test (tc_negativeTests, dash_mpdparser_wrong_period_duration_inferred_from_next_mediaPresentationDuration); + tcase_add_test (tc_negativeTests, dash_mpdparser_negative_period_duration); tcase_add_test (tc_stringTests, dash_mpdparser_whitespace_strings); tcase_add_test (tc_stringTests, dash_mpdparser_rfc1738_strings);