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 C6752489C7 for ; Fri, 22 Dec 2023 11:52:03 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 79D7468D29F; Fri, 22 Dec 2023 13:52:00 +0200 (EET) Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1E9F968C8F1 for ; Fri, 22 Dec 2023 13:51:54 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 6CFBE240003 for ; Fri, 22 Dec 2023 11:51:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1703245913; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc; bh=C2s2hqlw4fJDvcJ0z+QlD7hkIMf311LTjrs3Ue2yHCI=; b=EI+KDNyEfANjgpcWpfyQq/mS0eIX8PuqHcNak1+CFW3XXDp/QySEu8Mr4jTbB/k9XR4GzO JNOnU1iQA4Blx66PC4tQxGrM0iw/qpkJnj8QXqgNi65g29pX2myssmd20RMuQYIv/TysXP 5yY6Cy6Q4R5eBEB2CR5RPbIw2lrdTaOFYyfLvjU5TZY6kgYxtaYV6hI1Llwy1yH4sC+My5 tLGRECiU28WRunW7DqdSNtafwBi3do6VJ3Rc94opvo4JkyFwDsNRMJqiUfR6g6VN8YaxC1 X8qrrdX0k+VmTnAVKQ0du0EHh3anNc15qAW/MM34POjqCAn1rLTenqBXteBKhQ== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 22 Dec 2023 12:51:51 +0100 Message-Id: <20231222115152.12329-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 1/2] avfilter/edge_template: Fix small inputs with gaussian_blur() 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 MIME-Version: 1.0 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: Fixes: out of array access Fixes: Ticket10699 Fixes: poc5ffmpeg Found-by: Zeng Yunxiang Signed-off-by: Michael Niedermayer --- libavfilter/edge_template.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/libavfilter/edge_template.c b/libavfilter/edge_template.c index 14635c25af0..ce45e579db5 100644 --- a/libavfilter/edge_template.c +++ b/libavfilter/edge_template.c @@ -74,6 +74,7 @@ void fn(gaussian_blur)(int w, int h, uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, int src_stride) { + int j; pixel *srcp = (pixel *)src; pixel *dstp = (pixel *)dst; @@ -81,12 +82,17 @@ void fn(gaussian_blur)(int w, int h, src_linesize /= sizeof(pixel); dst_linesize /= sizeof(pixel); - memcpy(dstp, srcp, w*sizeof(pixel)); dstp += dst_linesize; srcp += src_linesize; - memcpy(dstp, srcp, w*sizeof(pixel)); dstp += dst_linesize; srcp += src_linesize; - for (int j = 2; j < h - 2; j++) { - dstp[0] = srcp[(0)*src_stride]; - dstp[1] = srcp[(1)*src_stride]; - for (int i = 2; i < w - 2; i++) { + for (j = 0; j < FFMIN(h, 2); j++) { + memcpy(dstp, srcp, w*sizeof(pixel)); + dstp += dst_linesize; + srcp += src_linesize; + } + + for (; j < h - 2; j++) { + int i; + for (i = 0; i < FFMIN(w, 2); i++) + dstp[i] = srcp[i*src_stride]; + for (; i < w - 2; i++) { /* Gaussian mask of size 5x5 with sigma = 1.4 */ dstp[i] = ((srcp[-2*src_linesize + (i-2)*src_stride] + srcp[2*src_linesize + (i-2)*src_stride]) * 2 + (srcp[-2*src_linesize + (i-1)*src_stride] + srcp[2*src_linesize + (i-1)*src_stride]) * 4 @@ -106,12 +112,15 @@ void fn(gaussian_blur)(int w, int h, + srcp[(i+1)*src_stride] * 12 + srcp[(i+2)*src_stride] * 5) / 159; } - dstp[w - 2] = srcp[(w - 2)*src_stride]; - dstp[w - 1] = srcp[(w - 1)*src_stride]; + for (; i < w; i++) + dstp[i] = srcp[i*src_stride]; dstp += dst_linesize; srcp += src_linesize; } - memcpy(dstp, srcp, w*sizeof(pixel)); dstp += dst_linesize; srcp += src_linesize; - memcpy(dstp, srcp, w*sizeof(pixel)); + for (; j < h; j++) { + memcpy(dstp, srcp, w*sizeof(pixel)); + dstp += dst_linesize; + srcp += src_linesize; + } } -- 2.17.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".