From patchwork Thu Mar 28 13:15:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Tong1" X-Patchwork-Id: 47581 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:9f96:b0:1a3:b6bb:3029 with SMTP id mm22csp1313216pzb; Thu, 28 Mar 2024 06:16:41 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWAnZSYUmVKyrP70GDFOqcv40rBo6TDo06o+4btDI14q/tjlDPvIP4ZB1shKHCFWVcRVux1/6+EOVrIWVgKyGHyrTb3w6NgQZ1Aeg== X-Google-Smtp-Source: AGHT+IFZTh+meTYm3mjRXnDOFLSZ3PNDmwgND1H/2s1YSlqYuWhUIUxdRQtji+hqmKYIv77Jqr2M X-Received: by 2002:a50:8ace:0:b0:568:64a7:cd6e with SMTP id k14-20020a508ace000000b0056864a7cd6emr1908039edk.1.1711631800873; Thu, 28 Mar 2024 06:16:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711631800; cv=none; d=google.com; s=arc-20160816; b=NW6EbqZN52XaGP1lKa7z7oUuwn1Chj/TsAs/1XtqDUDRMPqn3x3/8Q8gk/Lz/H4Y03 /0TjmAMUzAi2Vb2dknQ/iOpPNiD+74DGyjB4KerwNcdjJ1gmE5ix9Mg6DAb0cXpYUlmN 7IY5UHji7vScm5hrgPfZbtv2yK7MKAVg1oUDmt3SxdjEQMNxfhLAqXgfKzA1Gvg6iRQt wjb20ufUmsEKAaZFr5BbZC6LwwV146hb+CJi46l1T5zRdQxnx09P3/3ayn8X3sfSpmOX A8MmtRBHr7ScGZsPgfJla/FEh16V6zBuze+C+vjXhyLMEXudeoUfTweCIUN5b+UFmef4 AnAQ== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=StddOG/c6jAftVJX8In+yEzQkZSxXWNZF7pTMv4N9nk=; fh=CX/m9qTuMDwrotqtm4RkAOJT6yXlKL2vcfWDitFPXZs=; b=oE0el3yWORG6s8GKf0tusJN2V4+YnLAzxqNODmBmZXXYC5QInmq8okF7yh20WcD6rf mdCVJuQOTg+s/YZHE67pbLS8R74kt6ub119il2tE4BNQkTjlbA6MKMmeJRd7/zPcmYX4 /3sTe7/07kNc+kS40xLictIlegk6d8mnfSbbe45pTdGiO5ceOLxwE3+q+RsopmbVpJZK XKHB0cUjOiSYZH5rAPkK7wTSg4jtHJmGxYdXO8KZjNJDDCxAA/lo/uJQWwcVt8qTtWeY nxKlBDtedI+FO2bmAgjKgI9LuoAREewyat0fHrAAvczNLgUCM1TZ+gkjy2YRNxkNLWA4 nBQw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=Tdxyvnz0; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id x18-20020a05640226d200b0056c5425b473si554861edd.76.2024.03.28.06.16.40; Thu, 28 Mar 2024 06:16:40 -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; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=Tdxyvnz0; 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 AF29168D65A; Thu, 28 Mar 2024 15:16:36 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 347DE68BFDF for ; Thu, 28 Mar 2024 15:16:29 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711631796; x=1743167796; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=YlOoZWgrI2SG0wNRTEZ3mCR/WDjSlf5TiomRgBGA1tw=; b=Tdxyvnz0WT3XnLOBFQO+pm6zcrRjZ7C/zWdmFRORf+DRNcfc/BEZYgUw OPkxNcKMv4bgG8ode0ohPhBmvul2Y2MynSsrCwkqHsogwXaPJT+VDSeWY G2RSmJKHAq+zZXOLrrU9te/sDZRXDHCY21dySpv8YmcaoOIF3WpXxDm7S yfkDzwZS/nd1Rx8D80xaUHvSVmMvscVHAlbljaqoX9Bru4nr4kS8iBkhJ hi55+crHGbc0qg+dW19lY354GGo46VDs+ld7GbsYOrYheq5X9nue/pBp2 aLDp6ah0qH8qCSLTDjrFPGbmGP17kQsyegwdsUo/ygPXBH8EuCAaoJFD+ g==; X-CSE-ConnectionGUID: zfdUcTOwTUuBhu6FfZKnYQ== X-CSE-MsgGUID: 8bS7uJcbSYCumzLX8WVH6Q== X-IronPort-AV: E=McAfee;i="6600,9927,11026"; a="29262470" X-IronPort-AV: E=Sophos;i="6.07,161,1708416000"; d="scan'208";a="29262470" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Mar 2024 06:16:28 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,161,1708416000"; d="scan'208";a="21140920" Received: from desktop-qn7n0nf.sh.intel.com (HELO localhost.localdomain) ([10.239.160.66]) by fmviesa003.fm.intel.com with ESMTP; 28 Mar 2024 06:16:26 -0700 From: tong1.wu-at-intel.com@ffmpeg.org To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Mar 2024 21:15:18 +0800 Message-ID: <20240328131518.766-1-tong1.wu@intel.com> X-Mailer: git-send-email 2.41.0.windows.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2NQuX0r09a4O 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). Signed-off-by: Tong Wu --- libavcodec/hevc_ps.c | 20 ++++++++++++++++---- libavcodec/hevc_ps.h | 4 +++- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index cbef3ef4cd..8b3a27a17c 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -449,6 +449,16 @@ static void uninit_vps(FFRefStructOpaque opaque, void *obj) av_freep(&vps->hdr); } +static int compare_vps(const HEVCVPS *vps1, const HEVCVPS *vps2) +{ + if ((!vps1->hdr && !vps2->hdr) || + (vps1->hdr && vps2->hdr && !memcmp(vps1->hdr, vps2->hdr, sizeof(*vps1->hdr)))) { + return !memcmp(vps1, vps2, offsetof(HEVCVPS, hdr)); + } + + return 0; +} + int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps) { @@ -545,9 +555,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 +581,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 {