From patchwork Fri Dec 2 12:51:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 1658 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.65.86 with SMTP id o83csp266859vsa; Fri, 2 Dec 2016 04:51:39 -0800 (PST) X-Received: by 10.28.24.74 with SMTP id 71mr2874438wmy.74.1480683099232; Fri, 02 Dec 2016 04:51:39 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id l203si2881889wmf.46.2016.12.02.04.51.38; Fri, 02 Dec 2016 04:51:39 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2927A689F13; Fri, 2 Dec 2016 14:51:28 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [5.9.118.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 751516898F6 for ; Fri, 2 Dec 2016 14:51:22 +0200 (EET) Received: from localhost.localdomain (ip4d16e5ec.dynamic.kabel-deutschland.de [77.22.229.236]) by btbn.de (Postfix) with ESMTPSA id 649371AA333; Fri, 2 Dec 2016 13:51:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rothenpieler.org; s=mail; t=1480683090; bh=LNX69BOmgiFEPkVClPWCWzCHz9G8il0pLUM9HUBALJ4=; h=From:To:Cc:Subject:Date; b=GTw8Es1QiduqyKz1bOStFVns1auLJ13whFYeE0rjN/ek0KW9FrPYnFStsMdrmr11C fUjayN8H3ZCNmxC8Hvn50jgEv3bCM8yphl09yuyp5DMLVvjUmgoPs6Bvmi+n2KXWpt WuQnjL3sIngm3gFluN/f0lyjVHPLUxTiHh3pmvpQ= From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Fri, 2 Dec 2016 13:51:24 +0100 Message-Id: <20161202125124.10712-1-timo@rothenpieler.org> X-Mailer: git-send-email 2.11.0.rc2 Subject: [FFmpeg-devel] [PATCH] avformat/utils: fix crashes in has_decode_delay_been_guessed X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Timo Rothenpieler MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" These paths can be taken when the actual underlying codec is not h264, but the user forces, for example via ffmpeg command line, a specific input decoder that happens to be a h264 decoder. In that case, the codecpar codec_id is set to h264, but the internal avctx is the one of, for example, an mpeg2 decoder, thus crashing in this function. Checking for the codec actually being h264 is not strictly neccesary to fix the crash, but a precaution to catch potential other unexpected codepaths. Fixes #5985 --- libavformat/utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libavformat/utils.c b/libavformat/utils.c index 345bbfe5fe..8e23c0c6ec 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -966,11 +966,14 @@ static int is_intra_only(enum AVCodecID id) static int has_decode_delay_been_guessed(AVStream *st) { - if (st->codecpar->codec_id != AV_CODEC_ID_H264) return 1; + if (st->codecpar->codec_id != AV_CODEC_ID_H264 || + st->internal->avctx->codec_id != AV_CODEC_ID_H264) + return 1; if (!st->info) // if we have left find_stream_info then nb_decoded_frames won't increase anymore for stream copy return 1; #if CONFIG_H264_DECODER - if (st->internal->avctx->has_b_frames && + if (st->internal->avctx->codec && !strcmp(st->internal->avctx->codec->name, "h264") && + st->internal->avctx->has_b_frames && avpriv_h264_has_num_reorder_frames(st->internal->avctx) == st->internal->avctx->has_b_frames) return 1; #endif