Skip to content

Commit 5746f68

Browse files
M. Swaanenburgmswaanen
authored andcommitted
Avoid potential buffer overrun
1 parent 8518210 commit 5746f68

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Release/src/utilities/base64.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ struct _triple_byte
5858
unsigned char _2_2 : 2;
5959
};
6060

61+
struct _double_byte
62+
{
63+
unsigned char _1_1 : 2;
64+
unsigned char _0 : 6;
65+
unsigned char _2_1 : 4;
66+
unsigned char _1_2 : 4;
67+
};
68+
69+
struct _single_byte
70+
{
71+
unsigned char _1_1 : 2;
72+
unsigned char _0 : 6;
73+
};
74+
6175
//
6276
// A note on the implementation of BASE64 encoding and decoding:
6377
//
@@ -227,7 +241,7 @@ utility::string_t _to_base64(const unsigned char *ptr, size_t size)
227241
{
228242
case 1:
229243
{
230-
const _triple_byte* record = reinterpret_cast<const _triple_byte*>(ptr);
244+
const _single_byte* record = reinterpret_cast<const _single_byte*>(ptr);
231245
unsigned char idx0 = record->_0;
232246
unsigned char idx1 = (record->_1_1 << 4);
233247
result.push_back(char_t(_base64_enctbl[idx0]));
@@ -238,7 +252,7 @@ utility::string_t _to_base64(const unsigned char *ptr, size_t size)
238252
}
239253
case 2:
240254
{
241-
const _triple_byte* record = reinterpret_cast<const _triple_byte*>(ptr);
255+
const _double_byte* record = reinterpret_cast<const _double_byte*>(ptr);
242256
unsigned char idx0 = record->_0;
243257
unsigned char idx1 = (record->_1_1 << 4) | record->_1_2;
244258
unsigned char idx2 = (record->_2_1 << 2);

0 commit comments

Comments
 (0)