History

avformat: Change avpriv_new_chapter() from O(n) to (1) in the common case

Fixes: timeout (slow -> 300ms) Fixes: 28876/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-5664824587583488

Michael Niedermayer committed 5 years ago

Commit a899d6c1 parent fc45d922 files · +13 −3Browse files

Unified · Split

2 files
  1. libavformat/internal.h +5 −0
  2. libavformat/utils.c +8 −3
libavformat/internal.h+5−0
@@ -142,6 +142,11 @@ struct AVFormatInternal { · 141 unmodified lines
142142 * Prefer the codec framerate for avg_frame_rate computation.
143143 */
144144 int prefer_codec_framerate;
145+
146+ /**
147+ * Set if chapter ids are strictly monotonic.
148+ */
149+ int chapter_ids_monotonic;
145150 };
146151
147152 struct AVStreamInternal {
libavformat/utils.c+8−3
@@ -4614,9 +4614,14 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, · 4613 unmodified lines
46144614 return NULL;
46154615 }
46164616
4617− for (i = 0; i < s->nb_chapters; i++)
4618− if (s->chapters[i]->id == id)
4619− chapter = s->chapters[i];
4617+ if (!s->nb_chapters) {
4618+ s->internal->chapter_ids_monotonic = 1;
4619+ } else if (!s->internal->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) {
4620+ s->internal->chapter_ids_monotonic = 0;
4621+ for (i = 0; i < s->nb_chapters; i++)
4622+ if (s->chapters[i]->id == id)
4623+ chapter = s->chapters[i];
4624+ }
46204625
46214626 if (!chapter) {
46224627 chapter = av_mallocz(sizeof(AVChapter));

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