Skip to content

BUG: Throw from DCMTKImageIO::ReadImageInformation on an unreadable file - #7237

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
edwardxuzhang1:dcmtk-unreadable-file
Nov 25, 2026
Merged

hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
edwardxuzhang1:dcmtk-unreadable-file

Conversation

@edwardxuzhang1

Copy link
Copy Markdown
Contributor

Replaces #7236, which GitHub closed after a bad force-push. Same fix; the test now also checks that its non-DICOM input file was written, per the review there.

DCMTKImageIO::ReadImageInformation() swallowed the exception from DCMTKFileReader::LoadFile() and continued with a null dataset, so reading any unreadable DICOM segfaulted in the next tag lookup. The exception now propagates, so callers get a catchable itk::ExceptionObject; a new GTest reads a non-DICOM file.

Fixes #6719

Testing and AI disclosure

ITKIODCMTKGTestDriver --gtest_filter=DCMTKImageIO.ReadImageInformationThrowsOnUnreadableFile segfaults (exit 139) without the fix and passes with it; ctest -L ITKIODCMTK passes 25/25 with ExternalData fetched. pre-commit hooks pass.

Prepared with AI assistance; I reviewed and tested every changed line.

PR Checklist

  • No API changes were made (or the changes have been approved)
  • No major design changes were made (or the changes have been approved)
  • Added test (or behavior not changed)
  • Updated API documentation (or API not changed)
  • Added license to new files (if any)
  • Added Python wrapping to new files (if any) as described in ITK Software Guide Section 9.5
  • Added ITK examples for all new major features (if any)

ReadImageInformation() caught the exception from
DCMTKFileReader::LoadFile(), printed a message, and continued with a
null dataset, so the next tag lookup crashed. Let the exception
propagate so callers receive an ExceptionObject.
@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:IO Issues affecting the IO module labels Nov 25, 2026
@dzenanz
dzenanz marked this pull request as ready for review November 25, 2026 20:25
@dzenanz
dzenanz requested a review from hjmjohnson November 25, 2026 20:25
@greptile-apps

greptile-apps Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

security Security Review

This PR appears safe to merge from a security standpoint.

What was checked
  • Traced the unreadable-DICOM path: the removed catch (...) previously left DCMTKFileReader's dataset null, and the next tag lookups in ReadImageInformation dereferenced it, crashing the process on a malformed file.
  • Confirmed the fix: LoadFile throws itk::ExceptionObject via itkGenericExceptionMacro, so callers now get a catchable exception instead of a segfault.
  • Checked the exception message contents: it carries only DCMTK's error text and the caller-supplied filename, so no data leaks beyond what the host app already has.
  • Scanned the rest of itkDCMTKImageIO.cxx for other swallowed LoadFile failures; the remaining catch blocks (CanReadFile, SeriesFileNames) fail closed and were not touched by this PR.
  • Reviewed the new test: it writes a small non-DICOM file only into the test output directory and asserts the throw; it introduces no new input path or dependency.

@greptile-apps

greptile-apps Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

DCMTKImageIO::ReadImageInformation() now lets file-loading errors reach callers instead of continuing with a null dataset.

  • Unreadable DICOM files now raise a catchable exception.

Reviews (1) · Last reviewed commit: "BUG: Throw from DCMTKImageIO::ReadImageI..." · Reviewed by Greptile

@hjmjohnson
hjmjohnson merged commit d7a6fb8 into InsightSoftwareConsortium:main Nov 25, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:IO Issues affecting the IO module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: DCMTKImageIO segfaults on any unreadable DICOM — swallowed LoadFile() failure leaves m_Dataset null

3 participants