From b5b3b0a3c20bacc7e7746acd66f876775b17e7df Mon Sep 17 00:00:00 2001 From: "Hans J. Johnson" Date: Fri, 13 Mar 2026 08:00:12 -0500 Subject: [PATCH] BUG: Add null checks after ReadHeader in IPLCommonImageIO MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The base class ReadHeader returns nullptr, and subclass overrides may also return null without throwing. Two call sites in ReadImageInformation dereference the result without null checks: 1. m_ImageHeader->modality (line 140) — null dereference when ReadHeader fails silently. Now throws itkExceptionMacro on null return. 2. curImageHeader->examNumber (line 223) — null dereference in the directory scan loop. Now skips null results with continue. Addresses nullability.NullPassedToNonnull and core.NullDereference findings from issue #1261. --- Modules/IO/IPL/src/itkIPLCommonImageIO.cxx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Modules/IO/IPL/src/itkIPLCommonImageIO.cxx b/Modules/IO/IPL/src/itkIPLCommonImageIO.cxx index b0698c00e55..858e6a7f0d7 100644 --- a/Modules/IO/IPL/src/itkIPLCommonImageIO.cxx +++ b/Modules/IO/IPL/src/itkIPLCommonImageIO.cxx @@ -133,9 +133,10 @@ IPLCommonImageIO::ReadImageInformation() FileNameToRead = _imagePath; this->m_ImageHeader = this->ReadHeader(FileNameToRead.c_str()); - // - // if anything fails in the header read, just let - // exceptions propagate up. + if (m_ImageHeader == nullptr) + { + itkExceptionMacro("ReadHeader failed for " << FileNameToRead); + } bool isCT = false; std::string modality = m_ImageHeader->modality; @@ -224,6 +225,10 @@ IPLCommonImageIO::ReadImageInformation() // throw an exception, and we'd just want to skip it. continue; } + if (curImageHeader == nullptr) + { + itkExceptionMacro("ReadHeader failed for " << fullPath); + } if ((((isCT) ? curImageHeader->examNumber : curImageHeader->echoNumber) == m_FilenameList->GetKey2()) && (curImageHeader->seriesNumber == m_FilenameList->GetKey1())) {