mirror of https://git.ffmpeg.org/ffmpeg.git
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>
This commit is contained in:
parent
d40dc64173
commit
4c777d52b9
|
@ -661,12 +661,15 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
|
||||||
if (!q) {
|
if (!q) {
|
||||||
char *o;
|
char *o;
|
||||||
/* parse timestr as S+ */
|
/* 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 */
|
if (o == p) /* the parsing didn't succeed */
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
dt.tm_min = 0;
|
if (errno == ERANGE)
|
||||||
dt.tm_hour = 0;
|
return AVERROR(ERANGE);
|
||||||
q = o;
|
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) {
|
if (duration) {
|
||||||
t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec;
|
|
||||||
if (q[0] == 'm' && q[1] == 's') {
|
if (q[0] == 'm' && q[1] == 's') {
|
||||||
suffix = 1000;
|
suffix = 1000;
|
||||||
microseconds /= 1000;
|
microseconds /= 1000;
|
||||||
|
@ -734,7 +736,11 @@ int av_parse_time(int64_t *timeval, const char *timestr, int duration)
|
||||||
if (*q)
|
if (*q)
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
|
if (INT64_MAX / suffix < t)
|
||||||
|
return AVERROR(ERANGE);
|
||||||
t *= suffix;
|
t *= suffix;
|
||||||
|
if (INT64_MAX - microseconds < t)
|
||||||
|
return AVERROR(ERANGE);
|
||||||
t += microseconds;
|
t += microseconds;
|
||||||
*timeval = negative ? -t : t;
|
*timeval = negative ? -t : t;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue