changeset 4211:afad57ac30ef

enforcing parameter "enforceAligned" in PamReader
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 21 Sep 2020 18:10:31 +0200
parents 7b14ddf795c5
children cb3af14626d4
files OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp OrthancFramework/Sources/Images/PamReader.h OrthancFramework/UnitTestsSources/ImageTests.cpp
diffstat 3 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Mon Sep 21 11:20:08 2020 +0200
+++ b/OrthancFramework/Sources/DicomParsing/ParsedDicomFile.cpp	Mon Sep 21 18:10:31 2020 +0200
@@ -1257,7 +1257,9 @@
 
       case MimeType_Pam:
       {
-        PamReader reader;
+        // "true" means "enforce memory alignment": This is slower,
+        // but possibly avoids crash related to non-aligned memory access
+        PamReader reader(true);
         reader.ReadFromMemory(content);
         EmbedImage(reader);
         break;
--- a/OrthancFramework/Sources/Images/PamReader.h	Mon Sep 21 11:20:08 2020 +0200
+++ b/OrthancFramework/Sources/Images/PamReader.h	Mon Sep 21 18:10:31 2020 +0200
@@ -61,9 +61,11 @@
 
   public:
     /**
-    See doc for field enforceAligned_
+    See doc for field enforceAligned_. Setting "enforceAligned" is slower,
+    but avoids possible crashes due to non-aligned memory access. It is
+    recommended to set this parameter to "true".
     */
-    PamReader(bool enforceAligned = false) :
+    explicit PamReader(bool enforceAligned) :
       enforceAligned_(enforceAligned),
       alignedImageBuffer_(NULL)
     {
--- a/OrthancFramework/UnitTestsSources/ImageTests.cpp	Mon Sep 21 11:20:08 2020 +0200
+++ b/OrthancFramework/UnitTestsSources/ImageTests.cpp	Mon Sep 21 18:10:31 2020 +0200
@@ -365,7 +365,7 @@
   w.WriteToMemory(s, accessor);
 
   {
-    Orthanc::PamReader r;
+    Orthanc::PamReader r(true);
     r.ReadFromMemory(s);
 
     ASSERT_EQ(r.GetFormat(), Orthanc::PixelFormat_Grayscale16);
@@ -411,7 +411,7 @@
     Orthanc::TemporaryFile tmp;
     tmp.Write(s);
 
-    Orthanc::PamReader r2;
+    Orthanc::PamReader r2(true);
     r2.ReadFromFile(tmp.GetPath());
 
     ASSERT_EQ(r2.GetFormat(), Orthanc::PixelFormat_Grayscale16);