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; + } } From patchwork Fri Dec 22 11:51:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 45290 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6623:b0:194:e134:edd4 with SMTP id n35csp1006071pzh; Fri, 22 Dec 2023 03:52:15 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnCCL0zZUIJR8xcJjv0Y6LL5x4lrwLD0dwuXb7IQeiHAkBNVLoQry+ow2FkhHrAVVBImIR X-Received: by 2002:a50:c046:0:b0:553:627f:4e48 with SMTP id u6-20020a50c046000000b00553627f4e48mr668528edd.55.1703245934770; Fri, 22 Dec 2023 03:52:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703245934; cv=none; d=google.com; s=arc-20160816; b=SUjNN1N2w7Gh+WktDN33WY23bt17JJrFAImmaL7x1mzl7txRVXPoplO9YKjQCHnc9E hDZ5pNuxvuuQH0vXBLbD7mSOeJ3NbL56XEEWqPNs6vZNiqM1RZiAscUejFKOA8iVVVA4 9xkWvwywvFh3oXbPGS0CvCG9iHtJmE5/KKz3kAvhBl2rUXwEelUSCio8IdcYv4cd3v3J jwYLke67ELliYjd0cIA3R/l+sDrMpeLBF70OzbA3tVEIlVarFsozc1J/iu6KF7ygIkQX RnIbKXZmM3o/N+2jGNFEyFXYUizx2hm1kE5+Z+Vp+MY+OJdO1JROGiJXBLbiU/hZIjLp ZffQ== 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:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to; bh=sXRK7CFyD3Gclnm78WDH6Tiuz6GR8mF/fPmJ1MSh6/g=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=nppkYR9GJXm+z/x9YI2sHVGSTSLxhr5zJKwFcYAEvKM+PSfcfyNyCCLbHWz7YVzqxf jvteIqdEL52zffffQuXazKPwtaZrDxG6jorqVHLXwZ+2Gm49ufsAfelVXlIN2c2p0JHT 61T0oU5ATLQ8n6XkJSgXYGjXEvDTH7BVts6Woo/AWmfyOZ7oRAGMELwUVqQvufy2bju5 DvOGZ8JV5HVr7zXNlJmYJfpWQ403iwuf4+uddulDHNrle4VDji5cXqFXA0Z+nDpHxRBA 8o7k392Rn9bQdH1PxajNZJ8oxcoOwQGNVpadeIZagLp1nBCoTmytryFmNYC+5qSop4er M5kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=GFKmQ5PV; 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 cx18-20020a05640222b200b00553a3d97b98si1762686edb.7.2023.12.22.03.52.14; Fri, 22 Dec 2023 03:52:14 -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=GFKmQ5PV; 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 CF79E68D2DE; Fri, 22 Dec 2023 13:52:02 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 30D2468D2D6 for ; Fri, 22 Dec 2023 13:51:56 +0200 (EET) Received: by mail.gandi.net (Postfix) with ESMTPSA id 81113FF815 for ; Fri, 22 Dec 2023 11:51:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1703245914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:in-reply-to:in-reply-to:references:references; bh=1H4I/KUv1857FU2YRjqhBHXUR0Octqppm5UWsG0Tp+s=; b=GFKmQ5PVaZifeq3GJbsD+94OK8+lQTtGhpJvRjTrvJvD1hiX25TFfk1ZoLieaZ6rHVSHYs XBoF7RJoO/0PgVpf3Ki1YbqKxX9qm7XQzSqrq/mqCuXD5rv0XmF1DOQ8P/IEI3i1dNNuKe 3V+mPaMXu6iRq8sm5tiIz90yjHrShKP5deLuGMZN7qkA5GkGjkhL2JzLmvacusLyjHMYXJ 8cSXC9M/9KUlyshv/oX0PdghREzRs6JqlximFoiBRQKyO034aCGJCcKjk1IbqnRq5iHuNu RsXNku3hZ3Itc4vLW63dskCkN4JeyAEwOgVaGCe5uP6xyUx9SZU0UB5Z5KeTnA== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Fri, 22 Dec 2023 12:51:52 +0100 Message-Id: <20231222115152.12329-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231222115152.12329-1-michael@niedermayer.cc> References: <20231222115152.12329-1-michael@niedermayer.cc> X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 2/2] avfilter/vf_weave: Fix odd height handling 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: I0p4BS+L8NAS Fixes: out of array access Fixes: tickets/10743/poc10ffmpeg Found-by: Zeng Yunxiang and Li Zeyuan Signed-off-by: Michael Niedermayer --- libavfilter/vf_weave.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_weave.c b/libavfilter/vf_weave.c index 84f3c5f337d..7ad29bdedbe 100644 --- a/libavfilter/vf_weave.c +++ b/libavfilter/vf_weave.c @@ -32,6 +32,7 @@ typedef struct WeaveContext { int double_weave; int nb_planes; int planeheight[4]; + int outheight[4]; int linesize[4]; AVFrame *prev; @@ -81,6 +82,9 @@ static int config_props_output(AVFilterLink *outlink) s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(inlink->h, desc->log2_chroma_h); s->planeheight[0] = s->planeheight[3] = inlink->h; + s->outheight[1] = s->outheight[2] = AV_CEIL_RSHIFT(2*inlink->h, desc->log2_chroma_h); + s->outheight[0] = s->outheight[3] = 2*inlink->h; + s->nb_planes = av_pix_fmt_count_planes(inlink->format); return 0; @@ -106,19 +110,20 @@ static int weave_slice(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) const int height = s->planeheight[i]; const int start = (height * jobnr) / nb_jobs; const int end = (height * (jobnr+1)) / nb_jobs; + const int compensation = 2*end > s->outheight[i]; av_image_copy_plane(out->data[i] + out->linesize[i] * field1 + out->linesize[i] * start * 2, out->linesize[i] * 2, in->data[i] + start * in->linesize[i], in->linesize[i], - s->linesize[i], end - start); + s->linesize[i], end - start - compensation * field1); av_image_copy_plane(out->data[i] + out->linesize[i] * field2 + out->linesize[i] * start * 2, out->linesize[i] * 2, s->prev->data[i] + start * s->prev->linesize[i], s->prev->linesize[i], - s->linesize[i], end - start); + s->linesize[i], end - start - compensation * field2); } return 0;