提交 a899d6ca 编写于 作者: M Michael Niedermayer

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/ffmpegSigned-off-by: NMichael Niedermayer <michael@niedermayer.cc>
上级 fc45d924
...@@ -142,6 +142,11 @@ struct AVFormatInternal { ...@@ -142,6 +142,11 @@ struct AVFormatInternal {
* Prefer the codec framerate for avg_frame_rate computation. * Prefer the codec framerate for avg_frame_rate computation.
*/ */
int prefer_codec_framerate; int prefer_codec_framerate;
/**
* Set if chapter ids are strictly monotonic.
*/
int chapter_ids_monotonic;
}; };
struct AVStreamInternal { struct AVStreamInternal {
......
...@@ -4614,9 +4614,14 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, ...@@ -4614,9 +4614,14 @@ AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base,
return NULL; return NULL;
} }
for (i = 0; i < s->nb_chapters; i++) if (!s->nb_chapters) {
if (s->chapters[i]->id == id) s->internal->chapter_ids_monotonic = 1;
chapter = s->chapters[i]; } 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) { if (!chapter) {
chapter = av_mallocz(sizeof(AVChapter)); chapter = av_mallocz(sizeof(AVChapter));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册