Commit a9f2550f authored by Jordan Petridis's avatar Jordan Petridis 🌱 Committed by Tim-Philipp Müller

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.

#532
parent 50a22896
......@@ -884,7 +884,13 @@ parse_subrip_time (const gchar * ts_string, GstClockTime * t)
/* make sure we have exactly three digits after he comma */
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;
len = strlen (p);
if (len > 3) {
......
......@@ -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
setup_subparse (void)
{
......@@ -374,6 +387,9 @@ GST_START_TEST (test_srt)
/* try with some WebVTT chunks */
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment