summaryrefslogtreecommitdiffstats
path: root/options/m_option.c
diff options
context:
space:
mode:
authorm154k1 <139042094+m154k1@users.noreply.github.com>2023-08-04 22:18:04 +0300
committersfan5 <sfan5@live.de>2023-08-06 13:48:17 +0200
commita173b477487d7bb7e6d20fd3d8f5d2ee4e0504a6 (patch)
tree04a98e63224837bb4c0a00b768c08daf1085b8e8 /options/m_option.c
parent8a7cd2048040aed2cf48768c1ff5518c296b1402 (diff)
downloadmpv-a173b477487d7bb7e6d20fd3d8f5d2ee4e0504a6.tar.bz2
mpv-a173b477487d7bb7e6d20fd3d8f5d2ee4e0504a6.tar.xz
options: fix relative time parsing
Currently relative time parsing is buggy when any of the non-leading units are non zero. For example, "-1:30" should result in -90 but currently it results in -30 (as a result of `-60 + 30`). Also reject timestamps where non-leading units are out of range. E.g. "1:100" would be rejected, but "100" will still be accepted as 100 seconds.
Diffstat (limited to 'options/m_option.c')
-rw-r--r--options/m_option.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/options/m_option.c b/options/m_option.c
index 1456931c00..eb83547356 100644
--- a/options/m_option.c
+++ b/options/m_option.c
@@ -2651,9 +2651,18 @@ static int parse_timestring(struct bstr str, double *time, char endchar)
int h, m, len;
double s;
*time = 0; /* ensure initialization for error cases */
+ bool neg = bstr_eatstart0(&str, "-");
+ if (!neg)
+ bstr_eatstart0(&str, "+");
+ if (bstrchr(str, '-') >= 0 || bstrchr(str, '+') >= 0)
+ return 0; /* the timestamp shouldn't contain anymore +/- after this point */
if (bstr_sscanf(str, "%d:%d:%lf%n", &h, &m, &s, &len) >= 3) {
+ if (m >= 60 || s >= 60)
+ return 0; /* minutes or seconds are out of range */
*time = 3600 * h + 60 * m + s;
} else if (bstr_sscanf(str, "%d:%lf%n", &m, &s, &len) >= 2) {
+ if (s >= 60)
+ return 0; /* seconds are out of range */
*time = 60 * m + s;
} else if (bstr_sscanf(str, "%lf%n", &s, &len) >= 1) {
*time = s;
@@ -2664,6 +2673,8 @@ static int parse_timestring(struct bstr str, double *time, char endchar)
return 0; /* invalid extra characters at the end */
if (!isfinite(*time))
return 0;
+ if (neg)
+ *time = -*time;
return len;
}