# HG changeset patch # User Alain Mazy # Date 1759831471 -7200 # Node ID 0942549f71852ae957229afcb8859809d404f18d # Parent 4866ab5476a81895a1ef0137f83a4a1755b586db fix decoding of LUT with less than 256 entries diff -r 4866ab5476a8 -r 0942549f7185 NEWS --- a/NEWS Mon Oct 06 09:51:39 2025 +0200 +++ b/NEWS Tue Oct 07 12:04:31 2025 +0200 @@ -39,6 +39,8 @@ empty element in a sequence. This was preventing access to /dicom-web/../metadata routes and prevented visualization in e.g. the Stone Web viewer and OHIF. * Fix issue 252: Disallow colons in HTTP basic usernames +* Fix: Decoding of LUT with less than 256 entries: + https://discourse.orthanc-server.org/t/cannot-preview-dicom-file/6275 * Upgraded dependencies for static builds: - civetweb 1.16, including patch for CVE-2025-55763 diff -r 4866ab5476a8 -r 0942549f7185 OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp --- a/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp Mon Oct 06 09:51:39 2025 +0200 +++ b/OrthancFramework/Sources/DicomParsing/Internals/DicomImageDecoder.cpp Tue Oct 07 12:04:31 2025 +0200 @@ -428,19 +428,27 @@ lutBlue == NULL || pixelData == NULL) { - throw OrthancException(ErrorCode_NotImplemented); + throw OrthancException(ErrorCode_NotImplemented, "Inconsistent Palette Color Lookup Table"); } switch (format) { case PixelFormat_RGB24: { - if (r != "256\\0\\16" || - rc != 256 || - gc != 256 || - bc != 256) + std::vector splitR; + Toolbox::SplitString(splitR, r.c_str(), '\\'); + if (splitR.size() != 3) { - throw OrthancException(ErrorCode_NotImplemented); + 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 + + if (rc != paletteSize || gc != paletteSize || bc != paletteSize) + { + throw OrthancException(ErrorCode_NotImplemented, std::string("Palette Color Lookup Table Descriptor invalid palette size: '") + r.c_str() + "'"); } if (pixelLength != target->GetWidth() * target->GetHeight()) @@ -477,9 +485,9 @@ for (unsigned int x = 0; x < width; x++) { - p[0] = lutRed[*source] >> 8; - p[1] = lutGreen[*source] >> 8; - p[2] = lutBlue[*source] >> 8; + p[0] = lutRed[*source] >> offsetBits; + p[1] = lutGreen[*source] >> offsetBits; + p[2] = lutBlue[*source] >> offsetBits; source++; p += 3; } @@ -496,7 +504,7 @@ bc != 65536 || pixelLength != 2 * target->GetWidth() * target->GetHeight()) { - throw OrthancException(ErrorCode_NotImplemented); + throw OrthancException(ErrorCode_NotImplemented, std::string("Palette Color Lookup Table Descriptor not supported: '") + r.c_str() + "'"); } const uint16_t* source = reinterpret_cast(pixelData);