Skip to content

Commit

Permalink
Added check to make sure: HighBit < BitsAllocated.
Browse files Browse the repository at this point in the history
Added check to the image preprocessing to make sure that the value of
HighBit is always less than the value of BitsAllocated. Before, this
missing check could lead to memory corruption if an invalid combination
of values was retrieved from a malformed DICOM dataset.

Thanks to Emmanuel Tacheau from the Cisco Talos team
<[email protected]> for the report, sample file (PoC)
and detailed analysis. See TALOS-2024-2121 and CVE-2024-52333.
  • Loading branch information
jriesmeier committed Jan 3, 2025
1 parent 3827482 commit 03e851b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions dcmimgle/libsrc/diimage.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
*
* Copyright (C) 1996-2024, OFFIS e.V.
* Copyright (C) 1996-2025, OFFIS e.V.
* All rights reserved. See COPYRIGHT file for details.
*
* This software and supporting documentation were developed by
Expand Down Expand Up @@ -549,12 +549,18 @@ void DiImage::convertPixelData()
{
const unsigned long fsize = OFstatic_cast(unsigned long, Rows) * OFstatic_cast(unsigned long, Columns) *
OFstatic_cast(unsigned long, SamplesPerPixel);
if ((BitsAllocated < 1) || (BitsStored < 1) || (BitsAllocated < BitsStored) ||
(BitsStored > OFstatic_cast(Uint16, HighBit + 1)))
if ((BitsAllocated < 1) || (BitsStored < 1))
{
ImageStatus = EIS_InvalidValue;
DCMIMGLE_ERROR("invalid values for 'BitsAllocated' (" << BitsAllocated << "), "
<< "'BitsStored' (" << BitsStored << ") and/or 'HighBit' (" << HighBit << ")");
DCMIMGLE_ERROR("invalid value(s) for 'BitsAllocated' (" << BitsAllocated << "), "
<< "and/or 'BitsStored' (" << BitsStored << ")");
return;
}
else if ((BitsAllocated < BitsStored) || (BitsAllocated <= HighBit) || ((BitsStored - 1) > HighBit))
{
ImageStatus = EIS_InvalidValue;
DCMIMGLE_ERROR("invalid combination of values for 'BitsAllocated' (" << BitsAllocated << "), "
<< "'BitsStored' (" << BitsStored << ") and 'HighBit' (" << HighBit << ")");
return;
}
else if ((evr == EVR_OB) && (BitsStored <= 8))
Expand Down

0 comments on commit 03e851b

Please sign in to comment.