From patchwork Thu Nov 4 05:44:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenbin Chen X-Patchwork-Id: 31291 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a5e:a610:0:0:0:0:0 with SMTP id q16csp146181ioi; Wed, 3 Nov 2021 22:48:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwviwCiFthoJfbBfygcwPJRNEJQFLWYYc9inUG0W5cosrQZY4RUSxUzm0T2ADxb8zCQrCR0 X-Received: by 2002:a05:6402:2550:: with SMTP id l16mr27385003edb.142.1636004924089; Wed, 03 Nov 2021 22:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636004924; cv=none; d=google.com; s=arc-20160816; b=Okel8WNSoGMx9Z/a8c7l8kQ/oBRYimaBugLO0OPWQcZsOlB32F6p1L1lO9DVcX8Ve+ JDV9fUWszeHQPC6bVwLDHBgygklWEt4PcGmBB1JwdPOZ2dHs1Ii+6k9hteia3Zw9bJCx n6Giv+/tLaEcWe+OHHIzKyxeLeeMy0IeRInIoI2ftj4R5MfZatcYkETTaQGwxRakkYJQ 9uOlsJw2GNt7OdZVyMaA24TVi3ibWbzEfg3/BnNF5RbNrnklzAuJy6tFhITqN/CoUsDp VdVo6exdwOtHW89CkoXGxz5ach9xnRce2Q5k/Or1Sv6OC4NhglqFnvjnMSiu/Ue8nybr Jz7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=dBfB43HfCLYydx6wdS6bNbRyR98nPdmm0NZ7Li0vOYw=; b=wiMooKDKxCjDErPI5P76cMSl7QXYnU31uxXFaRaSX3ZxVw2ZBWXRQ8dg1hDwv4RzdT GbiyDSphFza3by45ObVxbShWbC6vILJFVFd/YALNy56vCCBajj9Zrb36ZvhTK12qMnbH TsSpTkHvlSyKVph2Zv9wVPEP9qoBryN1+HA6HJtAP8AdsinSdtP7iZg5aXjazA/jWVDk E5j7gjQpUvGtHdKxBLzaKhYCgV8+aaIIAzGfj/VK9l4h0k6dN5HHyooWT8/rwSLXEzU/ 39oMmddXKVWYrHMeir4e2LfZ6/8MqN7eseCiu3R1+juhY8kF6ZpO9L+qT6eiJ9BmBBVY 6wzw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h26si5694077edw.33.2021.11.03.22.48.43; Wed, 03 Nov 2021 22:48:44 -0700 (PDT) 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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 20D0468AD12; Thu, 4 Nov 2021 07:48:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F158968996A for ; Thu, 4 Nov 2021 07:48:21 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10157"; a="212398284" X-IronPort-AV: E=Sophos;i="5.87,208,1631602800"; d="scan'208";a="212398284" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2021 22:48:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,208,1631602800"; d="scan'208";a="639158174" Received: from chenwenbin-z390-aorus-ultra.sh.intel.com ([10.239.35.110]) by fmsmga001.fm.intel.com with ESMTP; 03 Nov 2021 22:48:17 -0700 From: Wenbin Chen To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Nov 2021 13:44:01 +0800 Message-Id: <20211104054403.1251208-2-wenbin.chen@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211104054403.1251208-1-wenbin.chen@intel.com> References: <20211104054403.1251208-1-wenbin.chen@intel.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/4] libavutil/hwcontext_qsv: fix a bug when malloc handle_pairs_internal 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: Wenbin Chen Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: oUBF15o8iuwc This commandline cause core dumped: ffmpeg -hwaccel vaapi -hwaccel_device /dev/dri/renderD128 \ -hwaccel_output_format vaapi -i input.264 \ -vf "hwmap=derive_device=qsv,format=qsv" \ -c:v h264_qsv output.264 reason: We use nb_surfaces to assign surface to handle_pairs_internal but handle_pairs_internal is alloced with the size of init_pool_size. This lead to access to illegal address. Now change it to use nb_surfaces to allocate handle_pairs_internal and the core dumped error is unseen. Also change D3D11VA to use nb_surfaces to align to VAAPI and DXVA2. Signed-off-by: Wenbin Chen --- libavutil/hwcontext_qsv.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index c18747f7eb..5a285fd25b 100644 --- a/libavutil/hwcontext_qsv.c +++ b/libavutil/hwcontext_qsv.c @@ -1123,8 +1123,7 @@ static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx, case AV_HWDEVICE_TYPE_VAAPI: { AVVAAPIFramesContext *src_hwctx = src_ctx->hwctx; - s->handle_pairs_internal = av_calloc(src_ctx->initial_pool_size, - sizeof(*s->handle_pairs_internal)); + s->handle_pairs_internal = av_calloc(src_hwctx->nb_surfaces, sizeof(*s->handle_pairs_internal)); if (!s->handle_pairs_internal) return AVERROR(ENOMEM); s->surfaces_internal = av_calloc(src_hwctx->nb_surfaces, @@ -1146,15 +1145,15 @@ static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx, case AV_HWDEVICE_TYPE_D3D11VA: { AVD3D11VAFramesContext *src_hwctx = src_ctx->hwctx; - s->handle_pairs_internal = av_calloc(src_ctx->initial_pool_size, + s->handle_pairs_internal = av_calloc(src_ctx->nb_surfaces, sizeof(*s->handle_pairs_internal)); if (!s->handle_pairs_internal) return AVERROR(ENOMEM); - s->surfaces_internal = av_calloc(src_ctx->initial_pool_size, + s->surfaces_internal = av_calloc(src_ctx->nb_surfaces, sizeof(*s->surfaces_internal)); if (!s->surfaces_internal) return AVERROR(ENOMEM); - for (i = 0; i < src_ctx->initial_pool_size; i++) { + for (i = 0; i < src_ctx->nb_surfaces; i++) { qsv_init_surface(dst_ctx, &s->surfaces_internal[i]); s->handle_pairs_internal[i].first = (mfxMemId)src_hwctx->texture_infos[i].texture; if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) { @@ -1164,7 +1163,7 @@ static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx, } s->surfaces_internal[i].Data.MemId = (mfxMemId)&s->handle_pairs_internal[i]; } - dst_hwctx->nb_surfaces = src_ctx->initial_pool_size; + dst_hwctx->nb_surfaces = src_ctx->nb_surfaces; if (src_hwctx->BindFlags & D3D11_BIND_RENDER_TARGET) { dst_hwctx->frame_type |= MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET; } else { @@ -1177,7 +1176,7 @@ static int qsv_frames_derive_to(AVHWFramesContext *dst_ctx, case AV_HWDEVICE_TYPE_DXVA2: { AVDXVA2FramesContext *src_hwctx = src_ctx->hwctx; - s->handle_pairs_internal = av_calloc(src_ctx->initial_pool_size, + s->handle_pairs_internal = av_calloc(src_ctx->nb_surfaces, sizeof(*s->handle_pairs_internal)); if (!s->handle_pairs_internal) return AVERROR(ENOMEM);