Skip to content

Commit b5b3b0a

Browse files
committed
BUG: Add null checks after ReadHeader in IPLCommonImageIO
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.
1 parent 22f6d27 commit b5b3b0a

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

Modules/IO/IPL/src/itkIPLCommonImageIO.cxx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ IPLCommonImageIO::ReadImageInformation()
133133
FileNameToRead = _imagePath;
134134

135135
this->m_ImageHeader = this->ReadHeader(FileNameToRead.c_str());
136-
//
137-
// if anything fails in the header read, just let
138-
// exceptions propagate up.
136+
if (m_ImageHeader == nullptr)
137+
{
138+
itkExceptionMacro("ReadHeader failed for " << FileNameToRead);
139+
}
139140

140141
bool isCT = false;
141142
std::string modality = m_ImageHeader->modality;
@@ -224,6 +225,10 @@ IPLCommonImageIO::ReadImageInformation()
224225
// throw an exception, and we'd just want to skip it.
225226
continue;
226227
}
228+
if (curImageHeader == nullptr)
229+
{
230+
itkExceptionMacro("ReadHeader failed for " << fullPath);
231+
}
227232
if ((((isCT) ? curImageHeader->examNumber : curImageHeader->echoNumber) == m_FilenameList->GetKey2()) &&
228233
(curImageHeader->seriesNumber == m_FilenameList->GetKey1()))
229234
{

0 commit comments

Comments
 (0)