From f0f2aca56611bf9430eb6edc23e9bd55cf96a26d Mon Sep 17 00:00:00 2001 From: Milan Zamazal Date: Mon, 29 Sep 2025 22:19:24 +0200 Subject: [PATCH] ipa: simple: agc: Prevent division by zero in AGC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the histogram size is non-zero but lower than the number of bins, yHistValsPerBin is zero and then the AGC processing crashes on division by it. Let's check yHistValsPerBin for being zero and stop AGC processing in such a case. The condition also covers the cases where histogramSize or yHistValsPerBinMod are zero. Tested-by: Barnabás Pőcze Signed-off-by: Milan Zamazal Reviewed-by: Kieran Bingham Reviewed-by: Hans de Goede Tested-by: Hans de Goede Signed-off-by: Kieran Bingham --- src/ipa/simple/algorithms/agc.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp index e0447cbd..189de770 100644 --- a/src/ipa/simple/algorithms/agc.cpp +++ b/src/ipa/simple/algorithms/agc.cpp @@ -145,6 +145,12 @@ void Agc::process(IPAContext &context, unsigned int denom = 0; unsigned int num = 0; + if (yHistValsPerBin == 0) { + LOG(IPASoftExposure, Debug) + << "Not adjusting exposure due to insufficient histogram data"; + return; + } + for (unsigned int i = 0; i < histogramSize; i++) { unsigned int idx = (i - (i / yHistValsPerBinMod)) / yHistValsPerBin; exposureBins[idx] += histogram[blackLevelHistIdx + i];