From patchwork Fri Dec 22 11:51:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 45289 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp1006026pzh; Fri, 22 Dec 2023 03:52:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEg/zJCTWqmXSMFKGxQmDbj4XsZlWBfnfOruCkTID+6h0K42GvdTgT4uDVFkFiZ71JW30Lg X-Received: by 2002:a05:6512:3d88:b0:50e:56ae:353e with SMTP id k8-20020a0565123d8800b0050e56ae353emr362558lfv.268.1703245927233; Fri, 22 Dec 2023 03:52:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703245927; cv=none; d=google.com; s=arc-20160816; b=hYqCVS9Sj4uPRGtwdPNG29zu3WIs1N6/E6vmPO9bSYfPSlOlDWDcrMPqwjPTCzYUCX sL9UJZ/ioaTxzfZeZkjGwYlTa/xb4/cragA3Q9CYn8TrUCZxy67xOhTwjOPwRb3xU9Jo iQHgkG5tCnR33U4ePJJSnOgjWipcea97uOu9oWcZkD7eiB1gV52J8jj4gyJIo+pFHFgF lIrKanCCKkn31bdp7q1teMAmj6qLDmhUV5FH/qnVParncb9WSEk/hqe3+uoXZGlTS+ii DsIS5h351ukyeoLdNIdvsj8Z06BPyFJpu+nEJn1G3LFJYMum4tyrFqpjkVA16PxS4AMf AvVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to; bh=mibjef7pItME7ZrdJXfFBG/1SEPLtlwGLeqezerNPjk=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=S68gx9NmRdRbKNeYWWViHgtd4gfp7DqAAr7PsKVG3214HSd9NhAfdIJngFvxb2eQio ORpsTeVLbdCkEUve2Jgw+SxFZljX3a/kl0PiYD71cPJe5+CgRdXqMbwI+IjiP87dr/OP Ojph7VSu5Fm6Vm3lDbmuOHQ7Nd5JhWVBwcOxvrrxNnyfU0udESB73VWdrscm8fWxvG0u JrpMClJUPWfH8tPyzJ/KN1kepAczjzCXe7m78/YIrh3z2LsSDHEEoRCk8zvzir99yMeL jFU7Hz7OXNtjpwDcild/4KGNEI4aHI63ys4cgV2Gu2EHQ/jkE0g6OrqUpCv5eOtVj9yI KPEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=EI+KDNyE; 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 o23-20020a509b17000000b00553773b88e8si1790547edi.485.2023.12.22.03.52.04; Fri, 22 Dec 2023 03:52:07 -0800 (PST) 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=@niedermayer.cc header.s=gm1 header.b=EI+KDNyE; 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 B5B8F68D2C1; Fri, 22 Dec 2023 13:52:00 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: qZyEKkiDWbfa 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; + } }