From e79cec02fbde156c56fc21fbd29b463830d1087c Mon Sep 17 00:00:00 2001 From: Milan Zamazal Date: Mon, 29 Sep 2025 22:19:18 +0200 Subject: [PATCH] libcamera: software_isp: Fix width adjustment in SwStatsCpu::setWindow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SwStatsCpu::setWindow reduces the window width by the added x-offset, to prevent exceeding image bounds. But if the window width is smaller than the x-offset, we get unsigned integer underflow. Fix it by setting the window width to 0 in such a case. Signed-off-by: Milan Zamazal Reviewed-by: Barnabás Pőcze Reviewed-by: Hans de Goede Tested-by: Hans de Goede Signed-off-by: Kieran Bingham --- src/libcamera/software_isp/swstats_cpu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 634ebfc3..43d8d79e 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -438,7 +438,7 @@ void SwStatsCpu::setWindow(const Rectangle &window) window_.y &= ~(patternSize_.height - 1); /* width_ - xShift_ to make sure the window fits */ - window_.width -= xShift_; + window_.width = (window_.width > xShift_ ? window_.width - xShift_ : 0); window_.width &= ~(patternSize_.width - 1); window_.height &= ~(patternSize_.height - 1); }