diff OrthancServer/Sources/ServerContext.cpp @ 4500:3b4940bca158

added safeguards in Orthanc::FileInfo
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 09 Feb 2021 14:49:30 +0100
parents 6f99949b2878
children 7d1eabfac6e0
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp	Tue Feb 09 14:25:21 2021 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Tue Feb 09 14:49:30 2021 +0100
@@ -571,12 +571,17 @@
 
       FileInfo dicomInfo = accessor.Write(dicom.GetBufferData(), dicom.GetBufferSize(), 
                                           FileContentType_Dicom, compression, storeMD5_);
-      FileInfo jsonInfo = accessor.Write(dicom.GetJson().toStyledString(), 
-                                         FileContentType_DicomAsJson, compression, storeMD5_);
 
       ServerIndex::Attachments attachments;
       attachments.push_back(dicomInfo);
-      attachments.push_back(jsonInfo);
+
+      FileInfo jsonInfo;
+      if (true /* TODO - !area_.HasReadRange() || !hasPixelDataOffset */)
+      {
+        jsonInfo = accessor.Write(dicom.GetJson().toStyledString(), 
+                                  FileContentType_DicomAsJson, compression, storeMD5_);
+        attachments.push_back(jsonInfo);
+      }
 
       typedef std::map<MetadataType, std::string>  InstanceMetadata;
       InstanceMetadata  instanceMetadata;
@@ -596,7 +601,11 @@
       if (status != StoreStatus_Success)
       {
         accessor.Remove(dicomInfo);
-        accessor.Remove(jsonInfo);
+
+        if (jsonInfo.IsValid())
+        {
+          accessor.Remove(jsonInfo);
+        }
       }
 
       switch (status)