[{"id":36088,"web_url":"https://patchwork.libcamera.org/comment/36088/","msgid":"<175943905807.3754595.13123370507815209384@ping.linuxembedded.co.uk>","date":"2025-10-02T21:04:18","subject":"Re: [PATCH v5 7/7] ipa: simple: agc: Prevent division by zero in AGC","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Milan Zamazal (2025-09-29 21:19:24)\n> If the histogram size is non-zero but lower than the number of bins,\n> yHistValsPerBin is zero and then the AGC processing crashes on division\n> by it.  Let's check yHistValsPerBin for being zero and stop AGC\n> processing in such a case.  The condition also covers the cases where\n> histogramSize or yHistValsPerBinMod are zero.\n> \n> Tested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n> Reviewed-by: Hans de Goede <hansg@kernel.org>\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Signed-off-by: Milan Zamazal <mzamazal@redhat.com>\n> ---\n>  src/ipa/simple/algorithms/agc.cpp | 6 ++++++\n>  1 file changed, 6 insertions(+)\n> \n> diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp\n> index c46bb0ebe..e47949ec4 100644\n> --- a/src/ipa/simple/algorithms/agc.cpp\n> +++ b/src/ipa/simple/algorithms/agc.cpp\n> @@ -124,6 +124,12 @@ void Agc::process(IPAContext &context,\n>         unsigned int denom = 0;\n>         unsigned int num = 0;\n>  \n> +       if (yHistValsPerBin == 0) {\n> +               LOG(IPASoftExposure, Debug)\n> +                       << \"Not adjusting exposure due to insufficient histogram data\";\n> +               return;\n> +       }\n> +\n>         for (unsigned int i = 0; i < histogramSize; i++) {\n>                 unsigned int idx = (i - (i / yHistValsPerBinMod)) / yHistValsPerBin;\n>                 exposureBins[idx] += histogram[blackLevelHistIdx + i];\n> -- \n> 2.51.0\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 C75C7C328C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  2 Oct 2025 21:04:23 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AC14F6B5F3;\n\tThu,  2 Oct 2025 23:04:22 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 951136B5A2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  2 Oct 2025 23:04:21 +0200 (CEST)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6B991F06;\n\tThu,  2 Oct 2025 23:02:51 +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=\"AHb4utRc\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1759438971;\n\tbh=n02EdNimGRdZhXgqjyLtaUy7f7/CBPa23W5gpymHOko=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=AHb4utRcFYWI5GPdkpw+S9mSuYAuxeMCWRDYsuoNIFb0xPkYXiE6q1wD2yAu7u/79\n\tFvGvklpmk2u1Yx/ae+90CgQzNbI0v0OfWoQLvhXkcXjk3yvDpyBC8pdRT4GR9sVK49\n\tOKlWbzo2c+rsw15n5QXjSsnlBWStRrc6GjF4v72Y=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20250929201924.45019-8-mzamazal@redhat.com>","References":"<20250929201924.45019-1-mzamazal@redhat.com>\n\t<20250929201924.45019-8-mzamazal@redhat.com>","Subject":"Re: [PATCH v5 7/7] ipa: simple: agc: Prevent division by zero in AGC","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Milan Zamazal <mzamazal@redhat.com>, pobrn@protonmail.com,\n\tmail@maciej.szmigiero.name, hansg@kernel.org, =?utf-8?b?QmFybmFiw6Fz?=\n\t=?utf-8?q?_P=C5=91cze?= <barnabas.pocze@ideasonboard.com>","To":"Milan Zamazal <mzamazal@redhat.com>, libcamera-devel@lists.libcamera.org","Date":"Thu, 02 Oct 2025 22:04:18 +0100","Message-ID":"<175943905807.3754595.13123370507815209384@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]