Commit 76d6c993d9 for ffmpeg
commit 76d6c993d9282d5d2486e8fc55e31796fe991a6b
Author: Kacper Michajłow <kasper93@gmail.com>
Date: Fri Dec 4 03:22:14 2026 +0100
avformat/dashdec: reject durations that cannot be converted to seconds
Every M was read as minutes, also the months before the T, and unknown
designators were skipped, so P1M was a minute, P1Y nothing and PT1H2X
an hour. Tell the date part from the time part and treat what is not a
number of seconds as invalid. Years and months have no fixed length,
they are accepted when there are none of them, as in P0Y0M0DT0H3M30S.
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 72cd4f5a8c..722dd272c9 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -223,37 +223,29 @@ static int64_t get_utc_date_time_insec(AVFormatContext *s, const char *datetime)
static int64_t get_duration_us(AVFormatContext *s, const char *duration, int64_t fallback)
{
/* ISO-8601 duration parser */
+ static const char designators[2][4] = { "YMD", "HMS" };
+ /* Years and months have no fixed length, only zero of them can be converted. */
+ static const int unit[2][3] = { { 0, 0, 86400 }, { 3600, 60, 1 } };
double seconds = 0;
int size = 0;
double value;
char type = '\0';
const char *ptr = duration;
+ int time = 0;
while (*ptr) {
if (*ptr == 'P' || *ptr == 'T') {
+ time |= *ptr == 'T';
ptr++;
continue;
}
if (av_sscanf(ptr, "%lf%c%n", &value, &type, &size) != 2 || value < 0)
goto invalid;
- switch (type) {
- case 'D':
- seconds += value * 86400;
- break;
- case 'H':
- seconds += value * 3600;
- break;
- case 'M':
- seconds += value * 60;
- break;
- case 'S':
- seconds += value;
- break;
- default:
- // handle invalid type
- break;
- }
+ const char *designator = strchr(designators[time], type);
+ if (!designator || !unit[time][designator - designators[time]] && value)
+ goto invalid;
+ seconds += value * unit[time][designator - designators[time]];
ptr += size;
}
if (seconds * AV_TIME_BASE < 0x1p63)