diff Sources/Plugin.cpp @ 55:41e3b79e7f4b nexus

added check of Nexus magic header
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 May 2024 15:19:08 +0200
parents 83b1abee3ece
children c322c949bd8e
line wrap: on
line diff
--- a/Sources/Plugin.cpp	Sat May 18 11:37:11 2024 +0200
+++ b/Sources/Plugin.cpp	Tue May 21 15:19:08 2024 +0200
@@ -949,6 +949,19 @@
                                     "POST body missing string field \"" + std::string(KEY_CONTENT) + "\"");
   }
 
+  std::string decoded;
+  Orthanc::Toolbox::DecodeBase64(decoded, body[KEY_CONTENT].asString());
+
+  if (decoded.size() < 4 ||
+      decoded[0] != 0x20 ||
+      decoded[1] != 0x73 ||
+      decoded[2] != 0x78 ||
+      decoded[3] != 0x4e)
+  {
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
+                                    "This is not a valid Nexus file, its magic header is incorrect");
+  }
+
   Json::Value creationBody = Json::objectValue;
 
   creationBody[KEY_TAGS] = body[KEY_TAGS];