From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id EBB294CA5D for ; Thu, 26 Jun 2025 14:07:45 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 39C5C68E167; Thu, 26 Jun 2025 17:07:40 +0300 (EEST) Received: from out162-62-57-137.mail.qq.com (out162-62-57-137.mail.qq.com [162.62.57.137]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 936AA68E15D for ; Thu, 26 Jun 2025 17:07:32 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1750946843; bh=Ur9vaKxUGuUK6mK2KXZ9hbyiWNrdLk5iV9cJOcOerGI=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=W0HA76KGs5Z3GAWDyqXAQtx4XAXjgVYE7ejaahYINERZE+e5Ef7wVenPOyA0rPdL6 0Wu9LHVHyMpH7jdDOQwrYpj1z+/vK3cYrHDCrioSqfvQnYOoxaOmd+rz9nl0IdDOMx Yw5eH2kgcQGJPI/VWbaCM5NvkC+Q43bmrzcaakYw= Received: from smtpclient.apple ([119.147.10.242]) by newxmesmtplogicsvrszc16-0.qq.com (NewEsmtp) with SMTP id 1D69B88A; Thu, 26 Jun 2025 22:07:22 +0800 X-QQ-mid: xmsmtpt1750946842twp76x2m8 Message-ID: X-QQ-XMAILINFO: MqG4KXyEKpQyCyub1yHivyQWVvhJ2ytII4UW0PKdzWl0B5uKfth8VpoOfdNRYA 9GfPpPO4Z/UEXQwQwMgVG8YRdbrmjQzcHle+S8/RWMly187NPJavIFYLogFusbrKn+MLdCyT8ZD9 RDck3ZSW2G2QFjM38balqF+ho6HN/2/OVwHckNnfYSLAXa7rLfiirqOBvh5SYWDg9C2SeamHohOC 8Q5qM+YTX/pW1WLlfe3Djay7UKcKbSHwspZhjLhjnJ13Abi/OKOCpMAigwy0iHU2Ojlh1hsI6ZLC Z22ltoOwD2B0G0g2BI73Dg/SB8w8jYdD/k1FXdfaR0XKqJQ1aIhXeyirevYTS6Rp0LxwC80c18i0 f/4BFREskXi6mPul0BiJYn8OH7/DLvkh+TAhbE3DcBgtP/ch+eSwksaDarnxxLyBBvmrfFDINHws Sylip/oj2BfRtWdMCyC2OAHcyHztus7mwKLESE4jMb+kkk892fKCeSeXLLZ0oxNYaE1kBphW6i4c Vj8NB/YZc1pKQ3QZ0JNwqRTnPhyG1Nc4NVwAhI7nnPwUUek9cxG4ml2GLaXbdIlCc/5h+vcJ67L3 rc5m3e6K2uaHk5HBpJvoGuwMN7mPaJQxG8bNR4yKKGCjqxjZe7aldmNxrntY0kZDcuDQV0eDDoai +YOMJX0WCZsR6urHto9KrlQgLwyY7iY5BWouj+/bHhu6p0A0d+dH5uoppyWag4lCiVDr9x9ZSgRT vB0Xuike3RcIeqrL0wQhFqNUePYfCVChPagEEq8JLbzkGYHUhXbB5IR+O/rSu7UnKYZ2kflRopVw KE+Ie8VQcvfCeAN7EnWWE+qOI+yJWCZCgOQhA/9ggN+E9AwXMwIG9doO5FSxnzopGa/fkQhVZa2O /BhEhPKTaEY4pSe2L0FDW008s60RcndvZ4gRdkMGAGK0LIleSW6+lGfMYiWXKOVSbViT7PPjtWa1 rRVIFvkld2xr2ziiIgPDVwr2OV5hofbEukXfmu0lqffIfZ5rW1ueCymAoGUiNih59lLO2uX3S23g xW/nZfAoA/dYKkClPoKIYPBgV7BsOkN/XjPbQQqrhpeI3yYVVr X-QQ-XMRINFO: MSVp+SPm3vtS1Vd6Y4Mggwc= Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) From: Zhao Zhili In-Reply-To: <20250626040707.1295-1-micro6947@gmail.com> Date: Thu, 26 Jun 2025 22:07:12 +0800 X-OQ-MSGID: <02BB27F1-0A64-41B4-9498-0CAFF004FBD0@foxmail.com> References: <20250626040707.1295-1-micro6947@gmail.com> To: FFmpeg development discussions and patches X-Mailer: Apple Mail (2.3826.500.181.1.5) Subject: Re: [FFmpeg-devel] [PATCH] libavcodec/utils: Ensure allocated buffer is zero-initialized 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: xjdeng 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: > On Jun 26, 2025, at 12:07, xjdeng wrote: > > In `av_fast_padded_mallocz`, the allocated buffer's zero-initialization is not guaranteed. > This is because it calls `av_fast_malloc`, which in turn calls `fast_malloc` with `zero_realloc=0`. > Consequently, the memory returned by the underlying `av_malloc` (used within `fast_malloc`) > is not guaranteed to be zero-initialized. > > Furthermore, if `*size` is adjusted to be greater than `min_size + AV_INPUT_BUFFER_PADDING_SIZE`, > the subsequent `memset` operation will not cover the entire allocated buffer, > leaving a portion of it uninitialized. > > To ensure the entire allocated buffer is properly zero-initialized, we should use `FFMAX` > to adjust the `memset` range. I think memset size is enough. size >= min_size + AV_INPUT_BUFFER_PADDING_SIZE. > > Signed-off-by: xjdeng > > --- > libavcodec/utils.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/libavcodec/utils.c b/libavcodec/utils.c > index f2686b6863..e2afce71ef 100644 > --- a/libavcodec/utils.c > +++ b/libavcodec/utils.c > @@ -72,8 +72,8 @@ void av_fast_padded_mallocz(void *ptr, unsigned int *size, size_t min_size) > return; > } > av_fast_malloc(p, size, min_size + AV_INPUT_BUFFER_PADDING_SIZE); > - if (*p) > - memset(*p, 0, min_size + AV_INPUT_BUFFER_PADDING_SIZE); > + if (*p) > + memset(*p, 0, FFMAX(*size, min_size + AV_INPUT_BUFFER_PADDING_SIZE)); > } > > int av_codec_is_encoder(const AVCodec *avcodec) > -- > 2.27.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". _______________________________________________ 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".