From 1da6cfeccb854b0e79addc18d6b4dfbd96fcbce5 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 4 Oct 2019 17:10:38 +0200 Subject: [PATCH] avformat/subtitles: Check nb_subs in ff_subtitles_queue_finalize() Fixes: null pointer dereference Fixes: 17828/clusterfuzz-testcase-minimized-ffmpeg_DEMUXER_fuzzer-5645915116797952 Fixes: Ticket8147 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer (cherry picked from commit 81b53913bbb97234e22187d1122948c351a3466d) Signed-off-by: Michael Niedermayer --- libavformat/subtitles.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c index 93c9ef05cf..1230e34d08 100644 --- a/libavformat/subtitles.c +++ b/libavformat/subtitles.c @@ -194,6 +194,9 @@ void ff_subtitles_queue_finalize(void *log_ctx, FFDemuxSubtitlesQueue *q) { int i; + if (!q->nb_subs) + return; + qsort(q->subs, q->nb_subs, sizeof(*q->subs), q->sort == SUB_SORT_TS_POS ? cmp_pkt_sub_ts_pos : cmp_pkt_sub_pos_ts);