History

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.

Dale Curtis committed 6 years ago

Commit f15007a1 parent f3bb5921 file · +3 −1Browse files

Unified · Split

libavformat/utils.c+3−1
@@ -2108,6 +2108,8 @@ void ff_configure_buffers_for_index(AVFormatContext *s, int64_t time_tolerance) · 2107 unmodified lines
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) · 21 unmodified lines
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;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t