[{"id":36000,"web_url":"https://patchwork.libcamera.org/comment/36000/","msgid":"<f1cb0302-97ad-4387-9def-20e20b8865fe@ideasonboard.com>","date":"2025-09-26T14:48:20","subject":"Re: [PATCH v4 1/7] libcamera: software_isp: Fix width adjustment in\n\tSwStatsCpu::setWindow","submitter":{"id":216,"url":"https://patchwork.libcamera.org/api/people/216/","name":"Barnabás Pőcze","email":"barnabas.pocze@ideasonboard.com"},"content":"2025. 09. 25. 21:28 keltezéssel, Milan Zamazal írta:\n> SwStatsCpu::setWindow reduces the window width by the added x-offset, to\n> prevent exceeding image bounds.  But if the window width is smaller than\n> the x-offset, we get unsigned integer underflow.  Fix it by setting the\n> window width to 0 in such a case.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>   src/libcamera/software_isp/swstats_cpu.cpp | 2 +-\n>   1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\n> index 4b77b3600..e8a1d52f2 100644\n> --- a/src/libcamera/software_isp/swstats_cpu.cpp\n> +++ b/src/libcamera/software_isp/swstats_cpu.cpp\n> @@ -426,7 +426,7 @@ void SwStatsCpu::setWindow(const Rectangle &window)\n>   \twindow_.y &= ~(patternSize_.height - 1);\n>   \n>   \t/* width_ - xShift_ to make sure the window fits */\n> -\twindow_.width -= xShift_;\n> +\twindow_.width = (window_.width > xShift_ ? window_.width - xShift_ : 0);\n\nThe `window_.width == 0` check in `SwStatsCpu::startFrame()` will now cause\na bit of a misleading message to be logged, but that is still better than\ngoing ahead with the wrapped around width.\n\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n\n\n>   \twindow_.width &= ~(patternSize_.width - 1);\n>   \twindow_.height &= ~(patternSize_.height - 1);\n>   }","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 69791BDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 26 Sep 2025 14:48:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4B4F76B5F3;\n\tFri, 26 Sep 2025 16:48:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 040A6613AB\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 26 Sep 2025 16:48:23 +0200 (CEST)","from [192.168.33.19] (185.221.140.70.nat.pool.zt.hu\n\t[185.221.140.70])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 7045114B0;\n\tFri, 26 Sep 2025 16:46:58 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"IDi5zauP\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1758898018;\n\tbh=+ccGVlyRAO60tYjumu8HXeJT2rXgo4bQrjHtsYnyC0g=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=IDi5zauPLyuU0Sj1LY84NP4ftBoO41h3/iJhCu3jG9KLbbgCXCdzxOsYaOPlE1J1K\n\tya2JzJpywXTXcnK3vU/Hqx+DgsEpbFfSksyc03vLuGmi9IxbP9l7s7Jf5ug+xE+F5X\n\tTi7phUeqMAFPISGZCKAQLapDtwhfb+3uSBsIDXow=","Message-ID":"<f1cb0302-97ad-4387-9def-20e20b8865fe@ideasonboard.com>","Date":"Fri, 26 Sep 2025 16:48:20 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v4 1/7] libcamera: software_isp: Fix width adjustment in\n\tSwStatsCpu::setWindow","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Cc":"mail@maciej.szmigiero.name","References":"<20250925192856.77881-1-mzamazal@redhat.com>\n\t<20250925192856.77881-2-mzamazal@redhat.com>","From":"=?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","Content-Language":"en-US, hu-HU","In-Reply-To":"<20250925192856.77881-2-mzamazal@redhat.com>","Content-Type":"text/plain; charset=UTF-8; format=flowed","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":36024,"web_url":"https://patchwork.libcamera.org/comment/36024/","msgid":"<ff100667-bfc6-4ff3-b045-a35367c44419@kernel.org>","date":"2025-09-29T11:10:35","subject":"Re: [PATCH v4 1/7] libcamera: software_isp: Fix width adjustment in\n\tSwStatsCpu::setWindow","submitter":{"id":239,"url":"https://patchwork.libcamera.org/api/people/239/","name":"Hans de Goede","email":"hansg@kernel.org"},"content":"Hi Milan,\n\nOn 25-Sep-25 21:28, Milan Zamazal wrote:\n> SwStatsCpu::setWindow reduces the window width by the added x-offset, to\n> prevent exceeding image bounds.  But if the window width is smaller than\n> the x-offset, we get unsigned integer underflow.  Fix it by setting the\n> window width to 0 in such a case.\n> \n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  src/libcamera/software_isp/swstats_cpu.cpp | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp\n> index 4b77b3600..e8a1d52f2 100644\n> --- a/src/libcamera/software_isp/swstats_cpu.cpp\n> +++ b/src/libcamera/software_isp/swstats_cpu.cpp\n> @@ -426,7 +426,7 @@ void SwStatsCpu::setWindow(const Rectangle &window)\n>  \twindow_.y &= ~(patternSize_.height - 1);\n>  \n>  \t/* width_ - xShift_ to make sure the window fits */\n> -\twindow_.width -= xShift_;\n> +\twindow_.width = (window_.width > xShift_ ? window_.width - xShift_ : 0);\n>  \twindow_.width &= ~(patternSize_.width - 1);\n>  \twindow_.height &= ~(patternSize_.height - 1);\n>  }\n\nAt the moment window_.width equals the debayer outputsize which is at least 2x2 (*),\nand xShift_ is 0 or 1, so this is not strictly necessary.\n\nStill I think this is a good thing to have with the upcoming changes to use\ndifferent stat-windows:\n\nReviewed-by: Hans de Goede <hansg@kernel.org>\n\nRegards,\n\nHans\n\n\n\n*) see sizes() method in debayer_cpu.cpp, this sets a min-outputsize of\npatternSize-width x patternSize-height which is a minimum of 2x2, this is\nenforced by DebayerCpu::configure()","headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id A3B66C324C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 29 Sep 2025 11:10:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id BAACE6B599;\n\tMon, 29 Sep 2025 13:10:42 +0200 (CEST)","from tor.source.kernel.org (tor.source.kernel.org\n\t[IPv6:2600:3c04:e001:324:0:1991:8:25])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8DF766B599\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 29 Sep 2025 13:10:40 +0200 (CEST)","from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58])\n\tby tor.source.kernel.org (Postfix) with ESMTP id F05796243D;\n\tMon, 29 Sep 2025 11:10:38 +0000 (UTC)","by smtp.kernel.org (Postfix) with ESMTPSA id A1B0AC4CEF4;\n\tMon, 29 Sep 2025 11:10:37 +0000 (UTC)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=kernel.org header.i=@kernel.org\n\theader.b=\"FaxVufCb\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org;\n\ts=k20201202; t=1759144238;\n\tbh=xJf3Gf1GYoAqo7YhtWWICPmp3QGqUTEJiUqROiWYxiI=;\n\th=Date:Subject:To:Cc:References:From:In-Reply-To:From;\n\tb=FaxVufCb2QCqkYmwgBtM5TIGaIKNVDZ0jM4Ni148qdKd4p8PIJARzTpV9UzBl3XIK\n\tHqGpGoJpNIJH/DjFXQ26Ms2v0BVY8zGS4Av5J7/K3Rm1kT3GwS2wUKp2nLVELHyqvC\n\tEum7U6ucD9QdEcb9SdWnAS3Shun4/lf5P4X8xv7OpsWI2jWodwOv4vdKFoyq/fmhbs\n\tTL3KNABQ5Jpnw35cuYxbuUYiiFQL6e9wsWqBynevtuZiHN4C5sVJKczM/V2zNyILMB\n\tripQ4jVmcaWdhnxLdQ9y0ljnwI/bgtm9atxUipzfICgrtsp4GD/VcahSJrVhjA41WJ\n\trSfKC3dvaS9ww==","Message-ID":"<ff100667-bfc6-4ff3-b045-a35367c44419@kernel.org>","Date":"Mon, 29 Sep 2025 13:10:35 +0200","MIME-Version":"1.0","User-Agent":"Mozilla Thunderbird","Subject":"Re: [PATCH v4 1/7] libcamera: software_isp: Fix width adjustment in\n\tSwStatsCpu::setWindow","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Cc":"pobrn@protonmail.com, mail@maciej.szmigiero.name","References":"<20250925192856.77881-1-mzamazal@redhat.com>\n\t<20250925192856.77881-2-mzamazal@redhat.com>","From":"Hans de Goede <hansg@kernel.org>","Content-Language":"en-US, nl","In-Reply-To":"<20250925192856.77881-2-mzamazal@redhat.com>","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"7bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]