Commit 90da187f authored by Michael Niedermayer's avatar Michael Niedermayer

avformat/utils: Check start/end before computing duration in update_stream_timings()

Fixes undefined behavior
Fixes: 637428.ogg
Found-by: 's avatarMatt Wolenetz <wolenetz@google.com>
Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent f88c8e0d
......@@ -2597,13 +2597,16 @@ static void update_stream_timings(AVFormatContext *ic)
if (ic->nb_programs > 1) {
for (i = 0; i < ic->nb_programs; i++) {
p = ic->programs[i];
if (p->start_time != AV_NOPTS_VALUE && p->end_time > p->start_time)
if (p->start_time != AV_NOPTS_VALUE &&
p->end_time > p->start_time &&
p->end_time - (uint64_t)p->start_time <= INT64_MAX)
duration = FFMAX(duration, p->end_time - p->start_time);
}
} else
} else if (end_time >= start_time && end_time - (uint64_t)start_time <= INT64_MAX) {
duration = FFMAX(duration, end_time - start_time);
}
}
}
if (duration != INT64_MIN && duration > 0 && ic->duration == AV_NOPTS_VALUE) {
ic->duration = duration;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment