# HG changeset patch # User Alain Mazy # Date 1779787525 -7200 # Node ID 8d72870bbfa19ee6c0889e251de9881ba01cfe65 # Parent 4176eb41cf29c306d719800beca5d3b131653fd2 check that the target image has a valid/reasonable size before transcoding to avoid possible crash or OOB during transcoding diff -r 4176eb41cf29 -r 8d72870bbfa1 OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp --- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp Thu May 21 14:45:25 2026 +0200 +++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.cpp Tue May 26 11:25:25 2026 +0200 @@ -503,6 +503,11 @@ } + void DicomImageInformation::ThrowIfInvalidFrameSize() const + { + GetFrameSize(); // GetFrameSize() will throw if the image dimensions are too large + } + unsigned int DicomImageInformation::GetUsefulTagLength() { return 256; diff -r 4176eb41cf29 -r 8d72870bbfa1 OrthancFramework/Sources/DicomFormat/DicomImageInformation.h --- a/OrthancFramework/Sources/DicomFormat/DicomImageInformation.h Thu May 21 14:45:25 2026 +0200 +++ b/OrthancFramework/Sources/DicomFormat/DicomImageInformation.h Tue May 26 11:25:25 2026 +0200 @@ -92,6 +92,8 @@ size_t GetFrameSize() const; + void ThrowIfInvalidFrameSize() const; + /** * This constant gives a bound on the maximum tag length that is * useful to class "DicomImageInformation", in order to avoid diff -r 4176eb41cf29 -r 8d72870bbfa1 OrthancServer/Sources/ServerContext.cpp --- a/OrthancServer/Sources/ServerContext.cpp Thu May 21 14:45:25 2026 +0200 +++ b/OrthancServer/Sources/ServerContext.cpp Tue May 26 11:25:25 2026 +0200 @@ -26,6 +26,7 @@ #include "../../OrthancFramework/Sources/Cache/SharedArchive.h" #include "../../OrthancFramework/Sources/DicomFormat/DicomElement.h" +#include "../../OrthancFramework/Sources/DicomFormat/DicomImageInformation.h" #include "../../OrthancFramework/Sources/DicomFormat/DicomStreamReader.h" #include "../../OrthancFramework/Sources/DicomNetworking/DicomStoreUserConnection.h" #include "../../OrthancFramework/Sources/DicomParsing/DicomModification.h" @@ -1064,6 +1065,15 @@ IDicomTranscoder::DicomImage transcoded; + if (dicom->HasPixelData()) + {// check that the target image has a valid/reasonable size before transcoding to avoid possible crash or OOB during transcoding + DicomMap summary; + dicom->GetSummary(summary); + + DicomImageInformation imageInfo(summary); + imageInfo.ThrowIfInvalidFrameSize(); + } + if (GetTranscoder().Transcode(transcoded, source, syntaxes, TranscodingSopInstanceUidMode_AllowNew /* allow new SOP instance UID */)) { std::unique_ptr tmp(transcoded.ReleaseAsParsedDicomFile());