Skip to content

Commit

Permalink
Fixed another issue with invalid mono images.
Browse files Browse the repository at this point in the history
Fixed issue when rendering an invalid monochrome DICOM image where the
number of pixels stored does not match the expected number of pixels.
In this case, only a single pixel is processed, but the pixel matrix is
much larger. Filling the rest of the pixel matrix with the smallest
possible value for the image is not working because of an optimized
memory usage (value would be out of range). Now, the pixel value to be
used is double-checked before it is actually filled into the "background"
of the image.

Thanks to Ding zhengzheng <[email protected]> for the report
and the sample file (PoC).
  • Loading branch information
jriesmeier committed Jan 17, 2025
1 parent 95b1eb9 commit 410ffe2
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions dcmimgle/include/dcmtk/dcmimgle/dimoipxt.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "dcmtk/ofstd/ofbmanip.h"
#include "dcmtk/ofstd/ofcast.h"
#include "dcmtk/ofstd/ofdiag.h" /* for DCMTK_DIAGNOSTIC macros */
#include "dcmtk/ofstd/oflimits.h" /* for OFnumeric_limits<> */

#include "dcmtk/dcmimgle/dimopxt.h"
#include "dcmtk/dcmimgle/diinpx.h"
Expand Down Expand Up @@ -72,9 +73,16 @@ class DiMonoInputPixelTemplate
rescale(pixel); // "copy" or reference pixel data
this->determineMinMax(OFstatic_cast(T3, this->Modality->getMinValue()), OFstatic_cast(T3, this->Modality->getMaxValue()));
}
/* erase empty part of the buffer (= fill the background with the smallest possible value) */
/* erase empty part of the buffer */
if ((this->Data != NULL) && (this->InputCount < this->Count))
OFBitmanipTemplate<T3>::setMem(this->Data + this->InputCount, OFstatic_cast(T3, this->Modality->getAbsMinimum()), this->Count - this->InputCount);
{
/* that means, fill the background with the smallest value that is possible */
const T3 minOut = OFnumeric_limits<T3>::min();
const T3 background = (this->Modality->getAbsMinimum() < OFstatic_cast(double, minOut)) ? minOut : OFstatic_cast(T3, this->Modality->getAbsMinimum());
const size_t count = (this->Count - this->InputCount);
DCMIMGLE_DEBUG("filing empty part of the intermediate pixel data (" << count << " pixels) with value = " << OFstatic_cast(double, background));
OFBitmanipTemplate<T3>::setMem(this->Data + this->InputCount, background, count);
}
}
}

Expand Down

0 comments on commit 410ffe2

Please sign in to comment.