From 812b746ef3ff80f97df9bf36e6e7c8833cd8d431 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 16 May 2016 20:32:41 +0200 Subject: [PATCH] Range control for Base64 decoding added --- include/WinStd/Base64.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/WinStd/Base64.h b/include/WinStd/Base64.h index 5a0f45fe..7fea4f5d 100644 --- a/include/WinStd/Base64.h +++ b/include/WinStd/Base64.h @@ -166,14 +166,14 @@ namespace winstd template inline void decode(_Out_ std::vector &out, _Out_ bool &is_last, _In_z_count_(size) const T *data, _In_ size_t size) { - size_t i = 0, j = 0, nibbles; + size_t i = 0, j = 0; is_last = false; for (;;) { if (num >= 4) { // Buffer full; decode it. - nibbles = decode(out, buf); + size_t nibbles = decode(out, buf); j += nibbles; num = 0; if (nibbles < 3) { @@ -185,7 +185,8 @@ namespace winstd if (i >= size || !data[i]) break; - if ((buf[num] = lookup[(unsigned char)data[i++]]) != 255) + int x = data[i++]; + if ((buf[num] = x < _countof(lookup) ? lookup[x] : 255) != 255) num++; } }