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 58D4347740 for ; Tue, 21 Nov 2023 04:38:39 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 28B2268CA21; Tue, 21 Nov 2023 06:38:37 +0200 (EET) Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A38DE68AC04 for ; Tue, 21 Nov 2023 06:38:30 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1700541515; x=1732077515; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=/kymWNRcTyfJHWXAvVq6g5qwHSLPUdpPUFZtcTzG8pk=; b=QiFtCqWsnNVat/v7zrglH2agP5X2IH7a77gf0rncOaE2S2tj+Y5SYaBw mP4AjmsUXoNGuEEJHxXreFGl1nZ5jHL41h83Zp+LhQLQeAHceWPZ2v5zM oPnK6c/xr6hof01c3sIeCVYsXzNQQmb/b+tgfw3OAUqwe3DEeUDt+s/J3 W4i1W2sZTMfBZB/siZL1eVsaBuAKBiwKEzHHIZqDuinJHemJI4JXscaUt +VMDR5bJ9AEJajaX0XU9V+O8jMgQA+GUlcXkJLsLyowf7JnCff7MGmPqH 0u4pSW6Ljk0NGptgBs6YDQplRNBAv6hW52hm7P+RKcMb6cAokkV8b9SC8 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10900"; a="395692824" X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="395692824" 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 20:38:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.04,215,1695711600"; d="scan'208";a="14786366" Received: from dvrscl.jf.intel.com ([10.54.72.26]) by fmviesa001.fm.intel.com with ESMTP; 20 Nov 2023 20:38:27 -0800 From: Dmitry Rogozhkin To: ffmpeg-devel@ffmpeg.org Date: Mon, 20 Nov 2023 20:37:52 -0800 Message-Id: <1700541472-12254-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 v4] 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) 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 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index ad39021..50c3995 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1838,17 +1838,25 @@ 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); + + *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".