# HG changeset patch # User Sebastien Jodogne # Date 1761745067 -3600 # Node ID 0d5e5d9df39d95f82e903866e9c58d4e411f5591 # Parent 39176cabe65a170dbdb94c1658687c73f5395f30 added safeguards in DecodeLookupTable() diff -r 39176cabe65a -r 0d5e5d9df39d OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp --- 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(splitR[0]); - unsigned long nbBitsUsedInLut = boost::lexical_cast(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(splitR[0]); + const unsigned int firstInputValueMapped = boost::lexical_cast(splitR[1]); + const unsigned int nbBitsUsedInLut = boost::lexical_cast(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() + "'"); }