diff Orthanc/Core/Toolbox.cpp @ 129:2c73a785c08e

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 14 May 2016 16:39:55 +0200
parents e8cfda4c8a2f
children d73006baca3f
line wrap: on
line diff
--- a/Orthanc/Core/Toolbox.cpp	Fri Apr 15 21:44:03 2016 +0200
+++ b/Orthanc/Core/Toolbox.cpp	Sat May 14 16:39:55 2016 +0200
@@ -582,12 +582,24 @@
   void Toolbox::DecodeBase64(std::string& result, 
                              const std::string& data)
   {
+    for (size_t i = 0; i < data.length(); i++)
+    {
+      if (!isalnum(data[i]) &&
+          data[i] != '+' &&
+          data[i] != '/' &&
+          data[i] != '=')
+      {
+        // This is not a valid character for a Base64 string
+        throw OrthancException(ErrorCode_BadFileFormat);
+      }
+    }
+
     result = base64_decode(data);
   }
 
 
 #  if BOOST_HAS_REGEX == 1
-  void Toolbox::DecodeDataUriScheme(std::string& mime,
+  bool Toolbox::DecodeDataUriScheme(std::string& mime,
                                     std::string& content,
                                     const std::string& source)
   {
@@ -599,10 +611,11 @@
     {
       mime = what[1];
       DecodeBase64(content, what[2]);
+      return true;
     }
     else
     {
-      throw OrthancException(ErrorCode_BadFileFormat);
+      return false;
     }
   }
 #  endif