Mercurial > hg > orthanc
changeset 6652:786fa27700ca machine-spirits
added safeguards for 1bpp PAM
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Fri, 20 Mar 2026 14:13:01 +0100 |
| parents | 7053ed3deb68 |
| children | 2640cf0fba20 |
| files | OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp |
| diffstat | 1 files changed, 15 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp Mon Mar 16 15:09:06 2026 +0100 +++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp Fri Mar 20 14:13:01 2026 +0100 @@ -461,13 +461,15 @@ size_t DicomImageInformation::GetFrameSize() const { + uint64_t totalFrameSize; + if (bitsStored_ == 1) { assert(GetWidth() % 8 == 0); if (GetChannelCount() == 1) { - return GetHeight() * GetWidth() / 8; + totalFrameSize = static_cast<uint64_t>(GetHeight()) * static_cast<uint64_t>(GetWidth()) / 8; } else { @@ -477,16 +479,19 @@ } else { - uint64_t totalFrameSize = static_cast<uint64_t>(GetHeight()) * - GetWidth() * - GetBytesPerValue() * - GetChannelCount(); + totalFrameSize = (static_cast<uint64_t>(GetHeight()) * + static_cast<uint64_t>(GetWidth()) * + static_cast<uint64_t>(GetBytesPerValue()) * + static_cast<uint64_t>(GetChannelCount())); + } - if (totalFrameSize > MAX_FRAME_SIZE) - { - throw OrthancException(ErrorCode_BadFileFormat, "DICOM Frame size overflow"); - } - + if (totalFrameSize > MAX_FRAME_SIZE || + static_cast<uint64_t>(static_cast<size_t>(totalFrameSize)) != totalFrameSize) + { + throw OrthancException(ErrorCode_BadFileFormat, "DICOM Frame size overflow"); + } + else + { return static_cast<size_t>(totalFrameSize); } }
