From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id B6D184E4C6 for ; Tue, 10 Jun 2025 02:31:58 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 414CD68CF71; Tue, 10 Jun 2025 05:31:54 +0300 (EEST) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 9BCF568CAD7 for ; Tue, 10 Jun 2025 05:31:47 +0300 (EEST) Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-235ea292956so48058855ad.1 for ; Mon, 09 Jun 2025 19:31:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749522706; x=1750127506; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=FdcUbT8bnZvbZsFRnaMy0+tunq2U0scruVkh3Sdjj5I=; b=GQAOidX6RAAcmRUoQ3mWGNbipII5PIFSw7XPkHHlhPhfkvseZ91JKElAqhhZd/tPKc qShGt6k8KZPiCubp1U6xuW2fHuALSzvJR4owAMxSLJws4/JDowvIDRETzz33xPiL8PGO XuuoWRZy7hn7t51wuEyJxA2BNHuRj+suMNJgFTlNxwt5tYMMO9N5gveY/lVu3hln+kPO nJTbQDSAtxfgP+ohz9fWmPq0FH8BRbgp6o1FYsYPlGKyu2Zn/NGPS2nGPOXYTjNpO9oT 9OoKQGNh71v+rD1nlA4Wjws0VEHf3m+NTpO5h9vvTe4gXtfEjPii6kwoGqblL5lgrneN iSrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749522706; x=1750127506; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FdcUbT8bnZvbZsFRnaMy0+tunq2U0scruVkh3Sdjj5I=; b=ViOAXurVAOw2QnXCVcvWEcAiPiGQrLG0CKf/2xUowrByWHYGGguOQlb7LvVyrWQAQU irsAY/tubF5QzBN711DHMuE+QfTjjxAvZVAXMHMO18qr35yUZEHFHbiiil2hvcE8Ot+p Gw5QrIESQk5MNFwRkLAERx16aF96mivsUqRn8o3OTJCFEy4m8umPh2TfVvroswGnAnB3 /H2vk9agdCbdobz6FY3qR7USMPhuTY1O2Yqj4m5vTBTl/yqxi5ARuJ8Oy7YfQQrbV8XZ VMQ6LCqcynrcp86hbmggxXjYs/H9/z54eru0XJpCfJn8OR7QQ+r9IkC8Ekn6q3/IzpiG 5USQ== X-Gm-Message-State: AOJu0YzdIICX2jquuVEM57FTN6CuQcT1RRi/4LH5DHLy4joN5FjEh3X+ TZbsuYeHxyz5EKzN/JSNfXrdXLgs4GOo6RDy+bbMeRzLB6fQd6dfvlJUVe/oL/mu X-Gm-Gg: ASbGncuibH1yG51Mc3Y0PFYUSqPFxdpauK0uz/B54g6f/RlKDyro/Vr9CRZZxcCsULA GKUZrX952R5Tde8iUOe+77NF2CkshazVNIq7P275U+7I6vzXbnF68lJwvLf7TlXHafETrcK9Ptf UxqFr5VEf0iw/jK7og/joIzzIUGA+XIxpNR4KUBf0hpaAFoLtNrtnPqr96/KTSKIB6OZK/dOkL9 dofBhvGFMlyqZlkE5lVjwm+lGPgZzK9ijrzG9RAI54OLL31AFaWHgWUGDug9SHcT7Wl5giyQqZN TsGlYmbZA7TaKKuNDjWt8oLixgPHVmvcJhG+EO4ZMnbd49lOczoXalAgD1dTdhepsSA2H7dPcCJ DLDO72HHo1Qw= X-Google-Smtp-Source: AGHT+IFzVi4Ooqm+b6E3UEtOF7f+7b9l4SgHDWicuhHAAP8Lwjm+ZKez4OQ4GGMPUIj6xTEgaORX7w== X-Received: by 2002:a17:902:ce0f:b0:235:880:cf8a with SMTP id d9443c01a7336-23601d04110mr250218605ad.15.1749522705557; Mon, 09 Jun 2025 19:31:45 -0700 (PDT) Received: from homestead.aragog.com ([2605:a601:a9a2:a100:67c:16ff:fe02:37f0]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23603514f78sm60932985ad.259.2025.06.09.19.31.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Jun 2025 19:31:45 -0700 (PDT) From: Pavel Koshevoy To: ffmpeg-devel@ffmpeg.org Date: Mon, 9 Jun 2025 20:31:43 -0600 Message-ID: <20250610023143.27169-1-pkoshevoy@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/demux: Fix segfault due to avcodec_open2 failure X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Pavel Koshevoy Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Fixes 'ffprobe 1_poc.mp4' segfault introduced with commit 0021484d05f9b0f032fa319399de6e24eea0c04f --- libavformat/demux.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libavformat/demux.c b/libavformat/demux.c index ecd4f40da9..d74d51e169 100644 --- a/libavformat/demux.c +++ b/libavformat/demux.c @@ -2078,8 +2078,8 @@ static int has_codec_parameters(const AVStream *st, const char **errmsg_ptr) static int try_decode_frame(AVFormatContext *s, AVStream *st, const AVPacket *pkt, AVDictionary **options) { - FFStream *const sti = ffstream(st); - AVCodecContext *const avctx = sti->avctx; + FFStream *sti = ffstream(st); + AVCodecContext *avctx = sti->avctx; const AVCodec *codec; int got_picture = 1, ret = 0; AVFrame *frame = av_frame_alloc(); @@ -2104,6 +2104,12 @@ static int try_decode_frame(AVFormatContext *s, AVStream *st, goto fail; } + if (avctx && avctx->codec != codec) { + avcodec_free_context(&avctx); + avctx = avcodec_alloc_context3(codec); + sti->avctx = avctx; + } + /* Force thread count to 1 since the H.264 decoder will not extract * SPS and PPS to extradata during multi-threaded decoding. */ av_dict_set(options ? options : &thread_opt, "threads", "1", 0); -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".