mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 02:31:03 +00:00
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:
parent
4d24f78c05
commit
5396ef6e45
2 changed files with 23 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue