From 0a108a37e15732ee61ee1f4be18553865f10bde4 Mon Sep 17 00:00:00 2001 From: Artem Smorodin Date: Sat, 26 Jul 2025 19:09:54 +0300 Subject: [PATCH] avformat/hlsenc: limit segments count to search duplicated segments filenames This linear search has a complexity of O(n). When ffmpeg attempts to parse a playlist containing approximately 100,000 segments, it effectively causes a hang for several minutes. This patch limits the allowed size for duplicate searches to a reasonable value. Now it takes between 0.5 and a few seconds (tested on different devices) instead of several minutes. Signed-off-by: Artem Smorodin Signed-off-by: Michael Niedermayer --- libavformat/hlsenc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c index a93d35ab75..d3db83093c 100644 --- a/libavformat/hlsenc.c +++ b/libavformat/hlsenc.c @@ -1172,7 +1172,7 @@ static int hls_append_segment(struct AVFormatContext *s, HLSContext *hls, if (hls->use_localtime_mkdir) { filename = vs->avf->url; } - if ((find_segment_by_filename(vs->segments, filename) || find_segment_by_filename(vs->old_segments, filename)) + if (vs->nb_entries <= 5000 && (find_segment_by_filename(vs->segments, filename) || find_segment_by_filename(vs->old_segments, filename)) && !byterange_mode) { av_log(hls, AV_LOG_WARNING, "Duplicated segment filename detected: %s\n", filename); }