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 0A4494A246 for ; Mon, 25 Mar 2024 18:00:43 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5CDFF68D469; Mon, 25 Mar 2024 20:00:42 +0200 (EET) Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1521368D19B for ; Mon, 25 Mar 2024 20:00:36 +0200 (EET) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id CB4B028D7844D for ; Mon, 25 Mar 2024 19:00:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1711389634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LZuJoDm89sVkcIBQbFtSWyzmt5bQ7mUuuGDeKxe/CWc=; b=kw1ySbEfg8JKuylzVmaMjjwUtoMzLhVCUX4DeZANzIAZSQ+mNMx0z3MXO5qJbpJmCAIiNS 5wQRFwpq0fKqIYdaWn9DI3kIqpX4H/OjGjO0clwgK/2qIHk+wfn1PhLlXKGcFFag9qKnFq QRBLWM8Url8uJjvllrjoZcY9AJFpKBqyiVAkOm3uo+f9aZPi06AzDUqX2UyTqH0o8Su/Ud wp+HDNwR0iz9r7pklb8/JzsGQLH+xvQjcdUgriOqe/me6CESe9hHCL9E6n0Mq1uiYlkD5c d/B466KuhTfUHu0R0hWYnyAEDdU5WYCVK8t8Y50AGiTqHg1REetr46YcfDd+Xw== Message-ID: Date: Mon, 25 Mar 2024 19:00:48 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: ffmpeg-devel@ffmpeg.org References: <20240323153026.1848-1-timo@rothenpieler.org> Content-Language: en-US, de-DE From: Timo Rothenpieler In-Reply-To: <20240323153026.1848-1-timo@rothenpieler.org> Subject: Re: [FFmpeg-devel] [PATCH] avfilter/vf_stack: round down internal item heights 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 23/03/2024 16:30, Timo Rothenpieler wrote: > Following situation: > Someone wants to stack two yuv420p frames of the size 3x3 pixel each. > Now the various AV_CEIL_RSHIFT() calculations calculate a height of 2 > pixel for each items subsampled planes. > However, for example in case of a vstack, the output frames will have a > height of 6, so the subsampled planes one of 3. > When the filter now tries to stack two items with a rounded-up height of > 2 into a frame with a height of 3, it'll write an entire extra line past > the end of a buffer. > > This patch instead rounds down all the item heights, to avoid this > situation. It's not ideal either, since now lines might be missed. But > that is definitely preferable over writing past the end of the > bufferThis patch instead rounds down all the item heights, to avoid this > situation. It's not ideal either, since now lines might be missed. But > that is definitely preferable over writing past the end of the buffer. > --- > libavfilter/vf_stack.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/libavfilter/vf_stack.c b/libavfilter/vf_stack.c > index 2bb3d9b1d2..46e7d6b7f5 100644 > --- a/libavfilter/vf_stack.c > +++ b/libavfilter/vf_stack.c > @@ -220,11 +220,11 @@ static int config_output(AVFilterLink *outlink) > return ret; > } > > - item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); > + item->height[1] = item->height[2] = inlink->h / (1 << s->desc->log2_chroma_h); > item->height[0] = item->height[3] = inlink->h; > > if (i) { > - item->y[1] = item->y[2] = AV_CEIL_RSHIFT(height, s->desc->log2_chroma_h); > + item->y[1] = item->y[2] = height / (1 << s->desc->log2_chroma_h); > item->y[0] = item->y[3] = height; > > height += ctx->inputs[i]->h; > @@ -244,7 +244,7 @@ static int config_output(AVFilterLink *outlink) > return ret; > } > > - item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); > + item->height[1] = item->height[2] = inlink->h / (1 << s->desc->log2_chroma_h); > item->height[0] = item->height[3] = inlink->h; > > if (i) { > @@ -278,14 +278,14 @@ static int config_output(AVFilterLink *outlink) > return ret; > } > > - item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); > + item->height[1] = item->height[2] = inlink->h / (1 << s->desc->log2_chroma_h); > item->height[0] = item->height[3] = inlink->h; > > if ((ret = av_image_fill_linesizes(item->x, inlink->format, inw)) < 0) { > return ret; > } > > - item->y[1] = item->y[2] = AV_CEIL_RSHIFT(inh, s->desc->log2_chroma_h); > + item->y[1] = item->y[2] = inh / (1 << s->desc->log2_chroma_h); > item->y[0] = item->y[3] = inh; > inw += ctx->inputs[k]->w; > } > @@ -322,7 +322,7 @@ static int config_output(AVFilterLink *outlink) > return ret; > } > > - item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); > + item->height[1] = item->height[2] = inlink->h / (1 << s->desc->log2_chroma_h); > item->height[0] = item->height[3] = inlink->h; > > p2 = arg; > @@ -370,7 +370,7 @@ static int config_output(AVFilterLink *outlink) > return ret; > } > > - item->y[1] = item->y[2] = AV_CEIL_RSHIFT(inh, s->desc->log2_chroma_h); > + item->y[1] = item->y[2] = inh / (1 << s->desc->log2_chroma_h); > item->y[0] = item->y[3] = inh; > > width = FFMAX(width, inlink->w + inw); ping I'm pretty sure this patch is not the correct solution. But right now there is a pretty nasty heap overflow in the filter that should be addressed somehow. _______________________________________________ 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".