X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavutil%2Fparseutils.c;h=167e8226482f72481e7ac8fbcebd9f8b4fb20a70;hb=a38eab8b7501440f872ff1af8a0c5482b7b3e532;hp=924c49d52cf65a99602f90e31aee3c49d1981d79;hpb=c0a647644f2703e1da980dcf988cefd81528d8c9;p=ffmpeg diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c index 924c49d52cf..167e8226482 100644 --- a/libavutil/parseutils.c +++ b/libavutil/parseutils.c @@ -504,7 +504,7 @@ char *av_small_strptime(const char *p, const char *fmt, struct tm *dt) switch(c) { case 'H': case 'J': - val = date_get_num(&p, 0, c == 'H' ? 23 : INT_MAX, 2); + val = date_get_num(&p, 0, c == 'H' ? 23 : INT_MAX, c == 'H' ? 2 : 4); if (val == -1) return NULL; @@ -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;