subparse: do not assert when failing to parse subrip timestamp

If a badly formatted was passed into `parse_subrip_time` it would
assert instead of exiting gracefully. This is problematic since
the input is provided by the user, and will trigger a crash.

https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/532
This commit is contained in:
Jordan Petridis 2019-01-11 17:43:03 +02:00 committed by Sebastian Dröge
parent 4d24f78c05
commit 5396ef6e45
2 changed files with 23 additions and 1 deletions

View file

@ -884,7 +884,13 @@ parse_subrip_time (const gchar * ts_string, GstClockTime * t)
/* make sure we have exactly three digits after he comma */ /* make sure we have exactly three digits after he comma */
p = strchr (s, ','); p = strchr (s, ',');
g_assert (p != NULL); if (p == NULL) {
/* If there isn't a ',' the timestamp is broken */
/* https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/issues/532#note_100179 */
GST_WARNING ("failed to parse subrip timestamp string '%s'", s);
return FALSE;
}
++p; ++p;
len = strlen (p); len = strlen (p);
if (len > 3) { if (len > 3) {

View file

@ -182,6 +182,19 @@ static SubParseInputChunk srt_input4[] = {
, ,
}; };
/* Test broken timestamp */
static SubParseInputChunk srt_input5[] = {
{
"1\n00:00:01,000 --> 00:00:02,000\n<v>some text\n\n",
1 * GST_SECOND, 2 * GST_SECOND, "some text"}
,
{
"2\n00:02:00,000 --> 00:03:0\n<v>some other text\n\n3\n00:00:03,000 --> 00:00:04,000\n<v>some more text\n\n",
3 * GST_SECOND, 4 * GST_SECOND, "some more text"}
,
};
static void static void
setup_subparse (void) setup_subparse (void)
{ {
@ -374,6 +387,9 @@ GST_START_TEST (test_srt)
/* try with some WebVTT chunks */ /* try with some WebVTT chunks */
test_srt_do_test (srt_input4, 0, G_N_ELEMENTS (srt_input4)); test_srt_do_test (srt_input4, 0, G_N_ELEMENTS (srt_input4));
/* try with some broken/cut-off timestamp */
test_srt_do_test (srt_input5, 0, G_N_ELEMENTS (srt_input5));
} }
GST_END_TEST; GST_END_TEST;