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 1980D4A527 for ; Fri, 29 Mar 2024 12:46:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F6DB68D5DF; Fri, 29 Mar 2024 14:46:00 +0200 (EET) Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6786468D450 for ; Fri, 29 Mar 2024 14:45:53 +0200 (EET) Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6e740fff1d8so1668359b3a.1 for ; Fri, 29 Mar 2024 05:45:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711716351; x=1712321151; darn=ffmpeg.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=jykfc7O8SJDqUTZyoWR9klwIC6S/9NsnuHhdPKRZXR0=; b=PHn0G8BELfagyi8Pd5qFKLdyf0fGYmsmgZbTgUjKxwIEpd02Xi05Q9+uacPFWOCdIZ xwoEj5cNAVqFmJ4w0OSFHQwu2N1bOAqPg6qdJC3KxT0+ahLHrQDbfy51c2nd3ulzVgg7 28Xnb8CfeVdiDGotMlYA0HEuJjxBLXO7Vy1pBlizk3PYHEp5PTjo2OJudCr5srwms6Gt B3PQO6Let+Ejdhg+zeTi1XfZR1vy+S42VNIiUeg0ps62SdiuaFpvRYYxu0yQ3CdE4QGb y2VzO9H1jHl/aVs0RBklIZImlRtrUxhpkb/h3zed4LvUaUT4gXDg0Ij9XM5UQnOEsGUS JgpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711716351; x=1712321151; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=jykfc7O8SJDqUTZyoWR9klwIC6S/9NsnuHhdPKRZXR0=; b=FQAZWhsmnIdsxWAlYxj4TrZmi5CCZR1x0FnznCJGvCccgsuS98r9q+HQsTbIYhM9NN lO5sXRnx+M5NCXkdVixVFB2C8r2RA59q8RIQ90yYmlSpGJufgunJQmTq3voXl02mx1H9 lG1rLuvL4129lF3Wh2nVyTnerVGeoMd20ceBp4L9IZ4e6UnJESzoL4JxT/Yle5ULyJ9L M/86aypJCIWflc52bG9fg/zw4eyvsdJu5dF58Ut5AyKJ3W3UDOR4YJeA1uTgWZmlhkoy T8CxeqyphBO2vfcqKHtd+tL6N37uPl2FAZ68/4KZY3YQRJBb+98rBkwq8Be0t4DWQ4AU TCDw== X-Gm-Message-State: AOJu0YzPKSoRNx1F+1G9sP4LfwwPtxWlLvq5/yJk+oOGS/KmSXvTWeS2 jK9grDpYWnGrfMEnIBZjtgPgM2sv1IG9b5+mleIuv9COo6S6KvaagkSbKh1P X-Google-Smtp-Source: AGHT+IFB9isNtVUU1+TcIjWpTEzZZJ9OJ5oOpsVSwonlX4w8gBmqqJDk24Xd6sCJXU8VBGNsm9nxnQ== X-Received: by 2002:a05:6a00:10c7:b0:6ea:e2d8:473 with SMTP id d7-20020a056a0010c700b006eae2d80473mr1994074pfu.6.1711716350592; Fri, 29 Mar 2024 05:45:50 -0700 (PDT) Received: from [192.168.0.15] ([190.194.167.233]) by smtp.gmail.com with ESMTPSA id fh32-20020a056a00392000b006ead3e66c6csm2943009pfb.39.2024.03.29.05.45.49 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 29 Mar 2024 05:45:49 -0700 (PDT) Message-ID: <3e6bb1b0-f862-4f3f-8b12-38620aa768a2@gmail.com> Date: Fri, 29 Mar 2024 09:45:56 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org References: <20240328131518.766-1-tong1.wu@intel.com> Content-Language: en-US From: James Almer In-Reply-To: <20240328131518.766-1-tong1.wu@intel.com> Subject: Re: [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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 3/28/2024 10:15 AM, tong1.wu-at-intel.com@ffmpeg.org wrote: > 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)))) { I think this should be vps1->vps_num_hrd_parameters * sizeof(*vps1->hdr), and done after the memcmp below to ensure vps_num_hrd_parameters is the same value in both structs. > + 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 { _______________________________________________ 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".