mirror of
https://github.com/nyanmisaka/ffmpeg-rockchip.git
synced 2025-10-16 22:01:15 +08:00
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 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
This commit is contained in:
@@ -4614,9 +4614,14 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < s->nb_chapters; i++)
|
||||
if (s->chapters[i]->id == id)
|
||||
chapter = s->chapters[i];
|
||||
if (!s->nb_chapters) {
|
||||
s->internal->chapter_ids_monotonic = 1;
|
||||
} else if (!s->internal->chapter_ids_monotonic || s->chapters[s->nb_chapters-1]->id >= id) {
|
||||
s->internal->chapter_ids_monotonic = 0;
|
||||
for (i = 0; i < s->nb_chapters; i++)
|
||||
if (s->chapters[i]->id == id)
|
||||
chapter = s->chapters[i];
|
||||
}
|
||||
|
||||
if (!chapter) {
|
||||
chapter = av_mallocz(sizeof(AVChapter));
|
||||
|
Reference in New Issue
Block a user