summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2018-09-30 22:34:41 +0200
committerMarton Balint <cus@passwd.hu>2018-10-07 20:26:29 +0200
commit4c777d52b9b1048ba92cab1a658c218c38282d25 (patch)
tree6a3fda6141cc0ac19d95b8cb1b93854fb2134345 /libavutil
parentd40dc64173a140755f36492a0c20fc41b27d66c3 (diff)
downloadffmpeg-4c777d52b9b1048ba92cab1a658c218c38282d25.tar.gz
avutil/parseutils: fix some overflows in duration calculations
Also properly return AVERROR(ERANGE) in case of actual overflows. Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/parseutils.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index 924c49d52c..59bec6cc9d 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -661,12 +661,15 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
if (!q) {
char *o;
/* parse timestr as S+ */
- dt.tm_sec = strtol(p, &o, 10);
+ errno = 0;
+ t = strtoll(p, &o, 10);
if (o == p) /* the parsing didn't succeed */
return AVERROR(EINVAL);
- dt.tm_min = 0;
- dt.tm_hour = 0;
+ if (errno == ERANGE)
+ return AVERROR(ERANGE);
q = o;
+ } else {
+ t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
}
}
@@ -688,7 +691,6 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
}
if (duration) {
- t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
if (q[0] == 'm' && q[1] == 's') {
suffix = 1000;
microseconds /= 1000;
@@ -734,7 +736,11 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
if (*q)
return AVERROR(EINVAL);
+ if (INT64_MAX / suffix < t)
+ return AVERROR(ERANGE);
t *= suffix;
+ if (INT64_MAX - microseconds < t)
+ return AVERROR(ERANGE);
t += microseconds;
*timeval = negative ? -t : t;
return 0;