Skip to content

fix(dicom): Fix rejected subimages, and reaching every frame - #5474

Open
lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-dicom
Open

lgritz wants to merge 1 commit into
AcademySoftwareFoundation:mainfrom
lgritz:lg-dicom

Conversation

@lgritz

@lgritz lgritz commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

This is follow-on work to PR #5468 -- after fixing the TIFF reader, I also turned up some similar issues in other format readers, and this PR addresses the issues in DICOM.

A failed seek_subimage left the reader thinking it was pointing at a subimage it had just refused, similar to what was uncovered for other formats in PR #5468 and #5470. Fixing that is the main point of this patch.

Second, along the way it was discovered that every frame past the first was unreachable. The subimage bound came from DicomImage::getFrameCount(), which is the number of frames the DicomImage loaded, not the number in the file. Instead, getNumberOfFrames() is the file's own count and is what we want.

But DICOMInput also never overrode current_subimage(), so it inherited the base class's "always 0" -- harmless while there could only be one subimage, wrong for multiple images.

Adds a testsuite for the DICOM format, which had none. The test writes its own small three-frame file rather than depending on an external image. Each frame is a different constant value, so the per-subimage hashes catch both losing the frames and reading the same frame repeatedly.

Assisted-by: Claude Code / Claude Opus 5

This is follow-on work to PR 5468 -- after fixing the TIFF reader, I
also turned up some similar issues in other format readers, and this PR
addresses the issues in DICOM.

Two problems in DICOMInput::seek_subimage(), both of which had been there
for as long as the reader has claimed to support subimages.

A failed seek left the reader pointing at a subimage it had just
refused, similar to what was uncovered for other formats in PR 5468
and 5470. Fixing that is the main point of this patch.

Second, along the way it was discovered that every frame past the
first was unreachable. The subimage bound came from
DicomImage::getFrameCount(), which is the number of frames the
DicomImage loaded, not the number in the file.  Instead,
getNumberOfFrames() is the file's own count and is what we want.

But DICOMInput also never overrode current_subimage(), so it inherited
the base class's "always 0" -- harmless while there could only be one
subimage, wrong for multiple images.

Adds a testsuite for the dicom format, which had none. The test writes its
own small three-frame file rather than depending on an external image. Each
frame is a different constant value, so the per-subimage hashes catch both
losing the frames and reading the same frame repeatedly.

Assisted-by: Claude Code / Claude Opus 5

Signed-off-by: Larry Gritz <lg@larrygritz.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant