From f6059dbb28ed1275e9daa73e58bad8a6e939e27a Mon Sep 17 00:00:00 2001 From: Dominique Belhachemi Date: Fri, 27 Nov 2026 10:15:23 -0500 Subject: [PATCH] BUG: Throw from RLEImage::Allocate when CounterType is too small Programs built without NDEBUG (e.g. in Debug mode) aborted when RLEImage's CounterType was too small for the image width. Throw an exception instead, so callers can handle it. Closes #7067 --- Modules/Filtering/RLEImage/include/itkRLEImage.hxx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Modules/Filtering/RLEImage/include/itkRLEImage.hxx b/Modules/Filtering/RLEImage/include/itkRLEImage.hxx index b70cca5870b..db0a1c3f695 100644 --- a/Modules/Filtering/RLEImage/include/itkRLEImage.hxx +++ b/Modules/Filtering/RLEImage/include/itkRLEImage.hxx @@ -45,9 +45,13 @@ RLEImage::Allocate(bool itkNotUsed(initial { itkAssertOrThrowMacro(this->GetBufferedRegion().GetSize(0) == this->GetLargestPossibleRegion().GetSize(0), "BufferedRegion must contain complete run-length lines!"); - itkAssertOrThrowMacro(this->GetLargestPossibleRegion().GetSize(0) <= - itk::SizeValueType(std::numeric_limits::max()), - "CounterType is not large enough to support image's X dimension!"); + const itk::SizeValueType xSize = this->GetLargestPossibleRegion().GetSize(0); + const itk::SizeValueType maxCount = std::numeric_limits::max(); + if (xSize > maxCount) + { + itkExceptionMacro("CounterType supports up to " << maxCount << " pixels per line, but the image's X dimension is " + << xSize); + } this->ComputeOffsetTable(); // SizeValueType num = static_cast(this->GetOffsetTable()[VImageDimension]); m_Buffer->Allocate(false);