diff options
author | Jordan Petridis <jordan@centricular.com> | 2019-01-11 17:43:03 +0200 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.com> | 2019-05-01 17:37:41 +0100 |
commit | a9f2550fbff1ce1d94a01f640a1affa632b698be (patch) | |
tree | 8eadd8127b056e4c715c10a3384adca76f1e21cd | |
parent | 50a22896364e085c69147dc280842044a4d9a4f6 (diff) | |
download | gstreamer-plugins-base-a9f2550fbff1ce1d94a01f640a1affa632b698be.tar.gz |
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
-rw-r--r-- | gst/subparse/gstsubparse.c | 8 | ||||
-rw-r--r-- | tests/check/elements/subparse.c | 16 |
2 files changed, 23 insertions, 1 deletions
diff --git a/gst/subparse/gstsubparse.c b/gst/subparse/gstsubparse.c index c527a94de..c3912ad2d 100644 --- a/gst/subparse/gstsubparse.c +++ b/gst/subparse/gstsubparse.c @@ -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) { diff --git a/tests/check/elements/subparse.c b/tests/check/elements/subparse.c index 022646497..9b94a2438 100644 --- a/tests/check/elements/subparse.c +++ b/tests/check/elements/subparse.c @@ -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; |