From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9FB6B482BF for ; Tue, 21 Nov 2023 05:58:09 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D403268A9AA; Tue, 21 Nov 2023 07:58:06 +0200 (EET) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CDC3868C99F for ; Tue, 21 Nov 2023 07:57:59 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700546285; x=1732082285; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=uwTjntibsBdMGkqTmPxPWPdcJr362vZM2ULvyTx5vPo=; b=Lu2b10hUuN6aDL5tJs4TBDVdnpSEbz1FS+JrR9Wa+f2mL/bzppc27X7z 4gcLw9WDNdCNADAyV7GGe/5n0+55zL6K/CIlRcEy4rdfg7Y9oOpjM+Su0 yf0CxI1kL4ZiqzopIo9RROWH8m58vNla1fGskdUS7ALjacmFNUAPbKAIG BMIPIdqHS4KzGT1x7omXERdnGhmnUJS+peiv2BWAeEMzFw1ZhQuGj2MBY p5XWJosUCIb+1hP7RrQkdQx0ME4aoAXydIn/GPshuksrdIUehz//DUTR+ 9MyzoFgL7W7Wtgwvh2Y55dW1CZQzOlkk4JG4T6mTGVbaAALbBE+IKDELG Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395700188" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395700188" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Nov 2023 21:57:56 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="14800815" Received: from dvrscl.jf.intel.com ([10.54.72.26]) by fmviesa001.fm.intel.com with ESMTP; 20 Nov 2023 21:57:56 -0800 From: Dmitry Rogozhkin To: ffmpeg-devel@ffmpeg.org Date: Mon, 20 Nov 2023 21:57:32 -0800 Message-Id: <1700546252-17490-1-git-send-email-dmitry.v.rogozhkin@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1699986151-24741-1-git-send-email-dmitry.v.rogozhkin@intel.com> References: <1699986151-24741-1-git-send-email-dmitry.v.rogozhkin@intel.com> Subject: [FFmpeg-devel] [PATCH v5] avcodec/decode: validate hw_frames_ctx when AVHWAccel.free_frame_priv is used 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: Christoph Reiter , Dmitry Rogozhkin , Lynne MIME-Version: 1.0 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: Validate that a hw_frames_ctx is available before using it for the AVHWAccel.free_frame_priv callback, and don't require it to be present when the callback is not in use by the HWAccel. v2: check for free_frame_priv (Hendrik) v3: return EINVAL (Christoph Reiter) v4: better commit message (Hendrik) v5: fix typo with missed frames_ctx (Lynne) See[1]: https://github.com/msys2/MINGW-packages/pull/19050 Fixes: be07145109 ("avcodec: add AVHWAccel.free_frame_priv callback") CC: Lynne CC: Christoph Reiter Signed-off-by: Dmitry Rogozhkin --- libavcodec/decode.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index ad39021..2cfb3fc 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1838,17 +1838,26 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private) { const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel); - AVHWFramesContext *frames_ctx; if (!hwaccel || !hwaccel->frame_priv_data_size) return 0; av_assert0(!*hwaccel_picture_private); - frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data; - *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0, - frames_ctx->device_ctx, - hwaccel->free_frame_priv); + if (hwaccel->free_frame_priv) { + AVHWFramesContext *frames_ctx; + + if (!avctx->hw_frames_ctx) + return AVERROR(EINVAL); + + frames_ctx = (AVHWFramesContext *) avctx->hw_frames_ctx->data; + *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0, + frames_ctx->device_ctx, + hwaccel->free_frame_priv); + } else { + *hwaccel_picture_private = ff_refstruct_allocz(hwaccel->frame_priv_data_size); + } + if (!*hwaccel_picture_private) return AVERROR(ENOMEM); -- 1.8.3.1 _______________________________________________ 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".