Mercurial > hg > orthanc
changeset 6357:0d5e5d9df39d
added safeguards in DecodeLookupTable()
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Wed, 29 Oct 2025 14:37:47 +0100 |
| parents | 39176cabe65a |
| children | aa4558c0529e |
| files | OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp |
| diffstat | 1 files changed, 13 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp Fri Oct 24 16:35:47 2025 +0200 +++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp Wed Oct 29 14:37:47 2025 +0100 @@ -442,11 +442,20 @@ throw OrthancException(ErrorCode_NotImplemented, std::string("Palette Color Lookup Table Descriptor invalid length: '") + r.c_str() + "'"); } - unsigned long paletteSize = boost::lexical_cast<unsigned long>(splitR[0]); - unsigned long nbBitsUsedInLut = boost::lexical_cast<unsigned long>(splitR[2]); // The LUT is always 16bits but only part of it might be used - unsigned long offsetBits = nbBitsUsedInLut - 8; // Since the LUT is 16bits and the target color value is 8bpp + const unsigned int paletteSize = boost::lexical_cast<unsigned int>(splitR[0]); + const unsigned int firstInputValueMapped = boost::lexical_cast<unsigned int>(splitR[1]); + const unsigned int nbBitsUsedInLut = boost::lexical_cast<unsigned int>(splitR[2]); // The LUT is always 16bits but only part of it might be used + if (firstInputValueMapped != 0 || + nbBitsUsedInLut < 8) + { + throw OrthancException(ErrorCode_NotImplemented, "Inconsistent Palette Color Lookup Table"); + } - if (rc != paletteSize || gc != paletteSize || bc != paletteSize) + const unsigned int offsetBits = nbBitsUsedInLut - 8; // Since the LUT is 16bits and the target color value is 8bpp + + if (rc != paletteSize || + gc != paletteSize || + bc != paletteSize) { throw OrthancException(ErrorCode_NotImplemented, std::string("Palette Color Lookup Table Descriptor invalid palette size: '") + r.c_str() + "'"); }
