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;
int64_t t, now64;
time_t now;
struct tm dt = { 0 }, tmbuf;
- int today = 0, negative = 0, microseconds = 0;
+ int today = 0, negative = 0, microseconds = 0, suffix = 1000000;
int i;
static const char * const date_fmt[] = {
"%Y - %m - %d",
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;
}
}
}
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;
+ q += 2;
+ } else if (q[0] == 'u' && q[1] == 's') {
+ suffix = 1;
+ microseconds = 0;
+ q += 2;
+ } else if (*q == 's')
+ q++;
} else {
int is_utc = *q == 'Z' || *q == 'z';
int tzoffset = 0;
if (*q)
return AVERROR(EINVAL);
- t *= 1000000;
+ if (INT64_MAX / suffix < t || t < INT64_MIN / suffix)
+ return AVERROR(ERANGE);
+ t *= suffix;
+ if (INT64_MAX - microseconds < t)
+ return AVERROR(ERANGE);
t += microseconds;
+ if (t == INT64_MIN && negative)
+ return AVERROR(ERANGE);
*timeval = negative ? -t : t;
return 0;
}