From 1e95ccb8e4d3217fcce2503ffdcf7bb90a1c8425 Mon Sep 17 00:00:00 2001 From: Bradley Lowekamp Date: Fri, 25 Sep 2026 15:33:29 -0400 Subject: [PATCH] BUG: Let ReadImageInformation succeed for unconfigured codecs ReadImageInformation only reports metadata derived from tags read independently of codec support, yet threw immediately whenever the compression codec was not configured. Defer that failure to Read(), which is what actually needs decoding. TIFFFindCODEC returns nullptr for schemes with no registered codec, leaving the codec name as the literal string "unknown"; report the raw compression tag value in that case instead. Issue: #6902 (cherry picked from commit c037e7e7733ba5a436bccd2ca2c4aea6d89ec982) --- Modules/IO/TIFF/src/itkTIFFImageIO.cxx | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Modules/IO/TIFF/src/itkTIFFImageIO.cxx b/Modules/IO/TIFF/src/itkTIFFImageIO.cxx index 02cdee6a417..673a46e6944 100644 --- a/Modules/IO/TIFF/src/itkTIFFImageIO.cxx +++ b/Modules/IO/TIFF/src/itkTIFFImageIO.cxx @@ -497,17 +497,9 @@ TIFFImageIO::ReadImageInformation() } - if (!m_InternalImage->CanRead()) + // Metadata stays inspectable without codec support; Read() reports the decode failure. + if (!m_InternalImage->CanRead() && TIFFIsCODECConfigured(this->m_InternalImage->m_Compression) == 1) { - // exception if compression is not supported - if (TIFFIsCODECConfigured(this->m_InternalImage->m_Compression) != 1) - { - const TIFFCodec * c = TIFFFindCODEC(this->m_InternalImage->m_Compression); - const char * codecName = (c != nullptr) ? static_cast(c->name) : "unknown"; - - itkExceptionMacro("TIFF CODEC \"" << codecName << "\" is not supported."); - } - char emsg[1024]; if (TIFFRGBAImageOK(m_InternalImage->m_Image, emsg) != 1) { @@ -1323,6 +1315,17 @@ TIFFImageIO::ReadCurrentPage(void * buffer, size_t pixelOffset) if (!m_InternalImage->CanRead()) { + if (TIFFIsCODECConfigured(this->m_InternalImage->m_Compression) != 1) + { + const TIFFCodec * c = TIFFFindCODEC(this->m_InternalImage->m_Compression); + + if (c != nullptr) + { + itkExceptionMacro("TIFF CODEC \"" << c->name << "\" is not supported."); + } + itkExceptionMacro("TIFF CODEC " << this->m_InternalImage->m_Compression << " is not supported."); + } + uint32_t * tempImage = nullptr; if (this->GetNumberOfComponents() == 4 && m_ComponentType == IOComponentEnum::UCHAR)