summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2013-08-28 10:32:06 +0200
committerFridrich Štrba <fridrich.strba@bluewin.ch>2013-08-28 10:32:06 +0200
commit12029a5fbbda72216c2a525f0680be0c2a346781 (patch)
tree4782fd40c69f3f1fc57c32d835e5d37a0d644f10
parent573868072b8c7b33b6a9562724ea0df96443b17c (diff)
Some versions of boost bomb on '=' padding characters
-rw-r--r--src/lib/libvisio_utils.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/lib/libvisio_utils.cpp b/src/lib/libvisio_utils.cpp
index 9ad520c..0f99d5c 100644
--- a/src/lib/libvisio_utils.cpp
+++ b/src/lib/libvisio_utils.cpp
@@ -28,7 +28,9 @@
* instead of those above.
*/
+#include <vector>
#include <string>
+#include <algorithm> // std::count
#include "VSDInternalStream.h"
#include "libvisio_utils.h"
@@ -126,16 +128,21 @@ double libvisio::readDouble(WPXInputStream *input)
void libvisio::appendFromBase64(WPXBinaryData &data, const unsigned char *base64Data, size_t base64DataLength)
{
- boost::iterator_range<const char *> base64String((const char *)base64Data, (const char *)base64Data + base64DataLength);
+ std::string base64String((const char *)base64Data, base64DataLength);
+ unsigned numPadding = std::count(base64String.begin(), base64String.end(), '=');
+ std::replace(base64String.begin(),base64String.end(),'=','A'); // replace '=' by base64 encoding of '\0'
typedef boost::archive::iterators::transform_width<
boost::archive::iterators::binary_from_base64<
boost::archive::iterators::remove_whitespace< std::string::const_iterator > >, 8, 6 > base64_decoder;
std::vector<unsigned char> buffer;
std::copy(base64_decoder(base64String.begin()), base64_decoder(base64String.end()), std::back_inserter(buffer));
-
if (!buffer.empty())
- data.append(&buffer[0], buffer.size());
+ {
+ buffer.erase(buffer.end()-numPadding,buffer.end()); // erase padding '\0' characters
+ if (!buffer.empty())
+ data.append(&buffer[0], buffer.size());
+ }
}
const ::WPXString libvisio::getColourString(const Colour &c)