From 73eb1775225fa1b8df689cb4a2a1805fe891fdb5 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Sun, 26 Jul 2026 15:12:44 -0700 Subject: [PATCH 1/2] fix(dicom): null-check DCMTK pixel-data accessors before use DicomImage::getInterData() and getOutputData() can return null when a corrupt DICOM's frame fails to decode, but their results were used without checking: getInterData() is immediately dereferenced via getData()/getRepresentation(), and getOutputData()'s pointer is stored and later memcpy'd in read_native_scanline(). The only guard was an OIIO_DASSERT, which compiles out in release builds, leaving a null-pointer dereference on malformed input. Check both and error cleanly. Assisted-by: Claude Code / Claude Opus 4.8 Signed-off-by: Larry Gritz --- src/dicom.imageio/dicominput.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/dicom.imageio/dicominput.cpp b/src/dicom.imageio/dicominput.cpp index a3ae6d6bac..ad537830a7 100644 --- a/src/dicom.imageio/dicominput.cpp +++ b/src/dicom.imageio/dicominput.cpp @@ -183,7 +183,12 @@ DICOMInput::seek_subimage(int subimage, int miplevel) ++m_subimage; } - m_dipixel = m_img->getInterData(); + m_dipixel = m_img->getInterData(); + if (!m_dipixel) { + errorfmt("Unable to read pixel data from DICOM file {}", m_filename); + m_img.reset(); + return false; + } m_internal_data = (const char*)m_dipixel->getData(); EP_Representation rep = m_dipixel->getRepresentation(); TypeDesc format; @@ -197,6 +202,11 @@ DICOMInput::seek_subimage(int subimage, int miplevel) default: break; } m_internal_data = (const char*)m_img->getOutputData(0, m_subimage, 0); + if (!m_internal_data) { + errorfmt("Unable to decode pixel data from DICOM file {}", m_filename); + m_img.reset(); + return false; + } EP_Interpretation photo = m_img->getPhotometricInterpretation(); struct PhotoTable { From 8a95ed9073430a0b20a8b6c4b535ac6e1ef0db42 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Sat, 8 Aug 2026 17:11:19 -0700 Subject: [PATCH 2/2] Fix a new nits found in review Signed-off-by: Larry Gritz --- src/dicom.imageio/dicominput.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/dicom.imageio/dicominput.cpp b/src/dicom.imageio/dicominput.cpp index ad537830a7..381d171c31 100644 --- a/src/dicom.imageio/dicominput.cpp +++ b/src/dicom.imageio/dicominput.cpp @@ -147,8 +147,7 @@ DICOMInput::seek_subimage(int subimage, int miplevel) if (subimage < m_subimage) { // Want an earlier subimage, Easier to close and start again - close(); - m_subimage = -1; + close(); // note: resets m_subimge to -1 } // Open if it's not already opened @@ -189,7 +188,6 @@ DICOMInput::seek_subimage(int subimage, int miplevel) m_img.reset(); return false; } - m_internal_data = (const char*)m_dipixel->getData(); EP_Representation rep = m_dipixel->getRepresentation(); TypeDesc format; switch (rep) {