[FFmpeg-devel] [PATCH] avformat/demux: Fix segfault due to avcodec_open2 failure (v2)
Pavel Koshevoy
pkoshevoy at gmail.com
Wed Jun 25 02:19:22 EEST 2025
If I don't hear any objections in the next 72 hours I will apply this at
that time, or later if I forget.
Pavel.
On Mon, Jun 23, 2025 at 2:37 PM Pavel Koshevoy <pkoshevoy at gmail.com> wrote:
> ping ... as this is a segfault fix for `ffplay/ffprobe -i 1_poc.mp4` I
> think it deserves some review/approval priority.
>
> On Mon, Jun 9, 2025 at 9:45 PM Pavel Koshevoy <pkoshevoy at gmail.com> wrote:
>
>> Fixes 'ffprobe 1_poc.mp4' segfault introduced with
>> commit 0021484d05f9b0f032fa319399de6e24eea0c04f
>>
>> codec_close should not assume that the codec_id did not change.
>> ---
>> libavformat/demux.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/libavformat/demux.c b/libavformat/demux.c
>> index ecd4f40da9..3749ab67a3 100644
>> --- a/libavformat/demux.c
>> +++ b/libavformat/demux.c
>> @@ -1292,9 +1292,15 @@ static int codec_close(FFStream *sti)
>> {
>> AVCodecContext *avctx_new = NULL;
>> AVCodecParameters *par_tmp = NULL;
>> + const AVCodec *new_codec = NULL;
>> int ret;
>>
>> - avctx_new = avcodec_alloc_context3(sti->avctx->codec);
>> + new_codec =
>> + (sti->avctx->codec_id != sti->pub.codecpar->codec_id) ?
>> + avcodec_find_decoder(sti->pub.codecpar->codec_id) :
>> + sti->avctx->codec;
>> +
>> + avctx_new = avcodec_alloc_context3(new_codec);
>> if (!avctx_new) {
>> ret = AVERROR(ENOMEM);
>> goto fail;
>> --
>> 2.43.0
>>
>>
More information about the ffmpeg-devel
mailing list