changeset 3772:a11d1d4b5849 transcoding

integration mainline->transcoding
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Mar 2020 19:20:15 +0100
parents 66e18aad0654 (current diff) 74889e6f6d68 (diff)
children d912b0b1628d
files Core/DicomParsing/FromDcmtkBridge.cpp
diffstat 3 files changed, 27 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/Core/DicomFormat/DicomMap.cpp	Tue Mar 17 16:39:38 2020 +0100
+++ b/Core/DicomFormat/DicomMap.cpp	Tue Mar 17 19:20:15 2020 +0100
@@ -745,9 +745,8 @@
   }
 
 
-  bool DicomMap::ParseDicomMetaInformation(DicomMap& result,
-                                           const char* dicom,
-                                           size_t size)
+  bool DicomMap::IsDicomFile(const char* dicom,
+                             size_t size)
   {
     /**
      * http://dicom.nema.org/medical/dicom/current/output/chtml/part10/chapter_7.html
@@ -756,11 +755,19 @@
      * account to determine whether the file is or is not a DICOM file.
      **/
 
-    if (size < 132 ||
-        dicom[128] != 'D' ||
-        dicom[129] != 'I' ||
-        dicom[130] != 'C' ||
-        dicom[131] != 'M')
+    return (size >= 132 &&
+            dicom[128] == 'D' &&
+            dicom[129] == 'I' &&
+            dicom[130] == 'C' &&
+            dicom[131] == 'M');
+  }
+    
+
+  bool DicomMap::ParseDicomMetaInformation(DicomMap& result,
+                                           const char* dicom,
+                                           size_t size)
+  {
+    if (!IsDicomFile(dicom, size))
     {
       return false;
     }
--- a/Core/DicomFormat/DicomMap.h	Tue Mar 17 16:39:38 2020 +0100
+++ b/Core/DicomFormat/DicomMap.h	Tue Mar 17 19:20:15 2020 +0100
@@ -180,6 +180,9 @@
 
     void GetTags(std::set<DicomTag>& tags) const;
 
+    static bool IsDicomFile(const char* dicom,
+                            size_t size);
+    
     static bool ParseDicomMetaInformation(DicomMap& result,
                                           const char* dicom,
                                           size_t size);
--- a/Core/DicomParsing/FromDcmtkBridge.cpp	Tue Mar 17 16:39:38 2020 +0100
+++ b/Core/DicomParsing/FromDcmtkBridge.cpp	Tue Mar 17 19:20:15 2020 +0100
@@ -1938,7 +1938,15 @@
     std::unique_ptr<DcmFileFormat> result(new DcmFileFormat);
 
     result->transferInit();
-    if (!result->read(is).good())
+
+    /**
+     * New in Orthanc 1.6.0: The "size" is given as an argument to the
+     * "read()" method. This can avoid huge memory consumption if
+     * parsing an invalid DICOM file, which can notably been observed
+     * by executing the integration test "test_upload_compressed" on
+     * valgrind running Orthanc.
+     **/
+    if (!result->read(is, EXS_Unknown, EGL_noChange, size).good())
     {
       throw OrthancException(ErrorCode_BadFileFormat,
                              "Cannot parse an invalid DICOM file (size: " +