diff Core/DicomParsing/FromDcmtkBridge.cpp @ 3771:74889e6f6d68

fix memory issues if parsing invalid DICOM file
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 17 Mar 2020 19:19:48 +0100
parents eb044cc49d51
children a11d1d4b5849
line wrap: on
line diff
--- a/Core/DicomParsing/FromDcmtkBridge.cpp	Tue Mar 17 16:36:14 2020 +0100
+++ b/Core/DicomParsing/FromDcmtkBridge.cpp	Tue Mar 17 19:19:48 2020 +0100
@@ -1879,7 +1879,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: " +