Skip to content

Commit f15007a

Browse files
dalecurtismichaelni
authored andcommitted
avformat/utils: Fix undefined behavior in ff_configure_buffers_for_index()
When e2_pts == INT64_MIN and e1_pts >= 0 the calculation of e2_pts - e1_pts will overflow an int64_t. Signed-off-by: Dale Curtis <[email protected]> Signed-off-by: Michael Niedermayer <[email protected]>
1 parent f3bb592 commit f15007a

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libavformat/utils.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,6 +2108,8 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance)
21082108
//We could use URLProtocol flags here but as many user applications do not use URLProtocols this would be unreliable
21092109
const char *proto = avio_find_protocol_name(s->url);
21102110

2111+
av_assert0(time_tolerance >= 0);
2112+
21112113
if (!proto) {
21122114
av_log(s, AV_LOG_INFO,
21132115
"Protocol name not provided, cannot determine if input is local or "
@@ -2135,7 +2137,7 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance)
21352137
for (; i2 < st2->nb_index_entries; i2++) {
21362138
AVIndexEntry *e2 = &st2->index_entries[i2];
21372139
int64_t e2_pts = av_rescale_q(e2->timestamp, st2->time_base, AV_TIME_BASE_Q);
2138-
if (e2_pts - e1_pts < time_tolerance)
2140+
if (e2_pts < e1_pts || e2_pts - (uint64_t)e1_pts < time_tolerance)
21392141
continue;
21402142
pos_delta = FFMAX(pos_delta, e1->pos - e2->pos);
21412143
break;

0 commit comments

Comments
 (0)