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 895454A542 for ; Fri, 29 Mar 2024 15:32:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 18B6C68D677; Fri, 29 Mar 2024 17:32:49 +0200 (EET) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F7AD68CF14 for ; Fri, 29 Mar 2024 17:32:41 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711726368; x=1743262368; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=7i48hA3sJFoEXHCtuBNRxqO+OJvH2Iq+1DOSqiEjocE=; b=PXerLQGnhwqOBoKRcZDJbLouOhlSeXOiaDB3FtSpg03oyYdRJRQ08XNS hJezObytAZG0h+qJzfeHBVOqSM7C/nFAQ6ONaLWZXg6Ho93pwGn7MbSna gXpCGIbfYEVM+Hq/TNhJBebwZG5LWRAfid+fFr6m+aA4tfIH5VVUZS2q2 2MNxaQK3OfcEi/cVbbI3TCDB7JMfS9xfnbOH20BS7r2j1CXiMxTfFq2XH 74wFQFk0ZIxZoO44TVM2AfgI2m+bIPkCXjXoCVIfXba4VvEvKMwwtRs5n 0fvgpeBUQ5CNohRkgeqMKWOjYxWPu8tVRleJ542uuz7gFMfyHl35LCVIl Q==; X-CSE-ConnectionGUID: wM5VKOPtQ+a6DWhPnbvpLQ== X-CSE-MsgGUID: vkIEX4X1T/aZuFu79oVRFg== X-IronPort-AV: E=McAfee;i="6600,9927,11028"; a="10726576" X-IronPort-AV: E=Sophos;i="6.07,165,1708416000"; d="scan'208";a="10726576" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Mar 2024 08:32:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,165,1708416000"; d="scan'208";a="21666155" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.66]) by fmviesa004.fm.intel.com with ESMTP; 29 Mar 2024 08:32:39 -0700 From: tong1.wu-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Date: Fri, 29 Mar 2024 23:31:20 +0800 Message-ID: <20240329153120.1210-1-tong1.wu@intel.com> X-Mailer: git-send-email 2.41.0.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3] avcodec/hevc_ps: fix the problem of memcmp losing effectiveness 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: Tong Wu , James Almer 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: From: Tong Wu HEVCHdrParams* receives a pointer which points to a dynamically allocated memory block. It causes the memcmp always returning 1. Add a function to do the comparision. A condition is also added to avoid malloc(0). Reviewed-by: James Almer Signed-off-by: Tong Wu --- libavcodec/hevc_ps.c | 19 +++++++++++++++---- libavcodec/hevc_ps.h | 4 +++- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index cbef3ef4cd..6475d86d7d 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -449,6 +449,15 @@ static void uninit_vps(FFRefStructOpaque opaque, void *obj) av_freep(&vps->hdr); } +static int compare_vps(const HEVCVPS *vps1, const HEVCVPS *vps2) +{ + if (!memcmp(vps1, vps2, offsetof(HEVCVPS, hdr))) + return !vps1->vps_num_hrd_parameters || + !memcmp(vps1->hdr, vps2->hdr, vps1->vps_num_hrd_parameters * sizeof(*vps1->hdr)); + + return 0; +} + int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps) { @@ -545,9 +554,11 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, goto err; } - vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); - if (!vps->hdr) - goto err; + if (vps->vps_num_hrd_parameters) { + vps->hdr = av_calloc(vps->vps_num_hrd_parameters, sizeof(*vps->hdr)); + if (!vps->hdr) + goto err; + } for (i = 0; i < vps->vps_num_hrd_parameters; i++) { int common_inf_present = 1; @@ -569,7 +580,7 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, } if (ps->vps_list[vps_id] && - !memcmp(ps->vps_list[vps_id], vps, sizeof(*vps))) { + compare_vps(ps->vps_list[vps_id], vps)) { ff_refstruct_unref(&vps); } else { remove_vps(ps, vps_id); diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h index cc75aeb8d3..0d8eaf2b3e 100644 --- a/libavcodec/hevc_ps.h +++ b/libavcodec/hevc_ps.h @@ -153,7 +153,6 @@ typedef struct PTL { typedef struct HEVCVPS { unsigned int vps_id; - HEVCHdrParams *hdr; uint8_t vps_temporal_id_nesting_flag; int vps_max_layers; @@ -175,6 +174,9 @@ typedef struct HEVCVPS { uint8_t data[4096]; int data_size; + /* Put this at the end of the structure to make it easier to calculate the + * size before this pointer, which is used for memcmp */ + HEVCHdrParams *hdr; } HEVCVPS; typedef struct ScalingList { -- 2.41.0.windows.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".