From 1102a9685460eb4314d39db7d9cbd0fbe82c2cfa Mon Sep 17 00:00:00 2001 From: Milan Zamazal Date: Mon, 29 Sep 2025 22:19:23 +0200 Subject: [PATCH] ipa: simple: blc: Prevent division by zero in BLC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When there are no values in the histogram, BLC simple IPA can crash on division by zero. We cannot get anything meaningful in such a case anyway, let's simply return from `process()' then. Tested-by: Barnabás Pőcze Reviewed-by: Barnabás Pőcze Reviewed-by: Maciej S. Szmigiero Reviewed-by: Hans de Goede Tested-by: Hans de Goede Signed-off-by: Milan Zamazal Signed-off-by: Kieran Bingham --- src/ipa/simple/algorithms/blc.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ipa/simple/algorithms/blc.cpp b/src/ipa/simple/algorithms/blc.cpp index 31eb356c..370385af 100644 --- a/src/ipa/simple/algorithms/blc.cpp +++ b/src/ipa/simple/algorithms/blc.cpp @@ -80,6 +80,11 @@ void BlackLevel::process(IPAContext &context, constexpr float ignoredPercentage = 0.02; const unsigned int total = std::accumulate(begin(histogram), end(histogram), 0); + if (total == 0) { + LOG(IPASoftBL, Debug) << "Not guessing black level, histogram is empty"; + return; + } + const unsigned int pixelThreshold = ignoredPercentage * total; const unsigned int histogramRatio = 256 / SwIspStats::kYHistogramSize; const unsigned int currentBlackIdx =