From 50b691312e84f3c933dfc5dfef119415f2ec5e0f Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Wed, 15 Apr 2026 02:50:05 -0500 Subject: [PATCH] BUG: Add zero-check guard in CumulativeGaussianCostFunction Guard the division by numberOfElements on line 55 against division-by-zero when m_OriginalDataArray is empty. The existing size-mismatch check did not catch the zero case. Cherry-pick of d7845feee7 from main, adapted for release-5.4 where the zero check was entirely absent (main had it in the wrong order). --- .../Optimizers/src/itkCumulativeGaussianCostFunction.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/Numerics/Optimizers/src/itkCumulativeGaussianCostFunction.cxx b/Modules/Numerics/Optimizers/src/itkCumulativeGaussianCostFunction.cxx index 8f725240ffe..1b3e314e81f 100644 --- a/Modules/Numerics/Optimizers/src/itkCumulativeGaussianCostFunction.cxx +++ b/Modules/Numerics/Optimizers/src/itkCumulativeGaussianCostFunction.cxx @@ -43,7 +43,7 @@ CumulativeGaussianCostFunction::CalculateFitError(MeasureType * setTestArray) // Use root mean square error as a measure of fit quality. unsigned int numberOfElements = m_OriginalDataArray.GetNumberOfElements(); - if (numberOfElements != setTestArray->GetNumberOfElements()) + if (numberOfElements == 0 || numberOfElements != setTestArray->GetNumberOfElements()) { return 1; }