diff Core/Toolbox.cpp @ 1988:e29aea2349b9

test validity of base64 strings
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 28 Apr 2016 17:45:03 +0200
parents 4b545a8b1f95
children e2dd40abce72
line wrap: on
line diff
--- a/Core/Toolbox.cpp	Tue Apr 26 17:40:55 2016 +0200
+++ b/Core/Toolbox.cpp	Thu Apr 28 17:45:03 2016 +0200
@@ -582,6 +582,18 @@
   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);
   }