BUG: Backport null checks after ReadHeader in IPLCommonImageIO#6064
Conversation
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 InsightSoftwareConsortium#1261.
|
| Filename | Overview |
|---|---|
| Modules/IO/IPL/src/itkIPLCommonImageIO.cxx | Adds two null checks after ReadHeader calls; first check (primary file) is straightforward and correct; second check (directory loop) throws an exception that propagates outside the surrounding try-catch, which may be overly strict compared to just continuing the loop. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[ReadImageInformation called] --> B["ReadHeader(primaryFile)"]
B --> C{nullptr?}
C -- yes --> D["itkExceptionMacro NEW\n(was: null-deref crash)"]
C -- no --> E[Read modality, add to list\nloop through directory]
E --> F["ReadHeader(curFile) in try-catch"]
F -- exception --> G[catch: continue to next file]
F -- nullptr --> H{nullptr? NEW}
H -- yes --> I["itkExceptionMacro\n(propagates OUTSIDE try-catch)"]
H -- no --> J[Compare series/echo keys]
J --> K[AddElementToList or skip]
K --> F
Reviews (1): Last reviewed commit: "BUG: Add null checks after ReadHeader in..." | Re-trigger Greptile
8505c1a
into
InsightSoftwareConsortium:release-5.4
Cherry-pick of 0eb1c42 from main. Adds null checks after
ReadHeadercalls inIPLCommonImageIOto prevent null pointer dereference.Backport for #6051 (Tier 1).