Commit e900d8e8 authored by Philipp Schafft's avatar Philipp Schafft 🦁

Fix: Fixed end-of-input bug in Base64 encoder

parent 648947fe
...@@ -421,18 +421,20 @@ char *util_base64_encode(const char *data, size_t len) { ...@@ -421,18 +421,20 @@ char *util_base64_encode(const char *data, size_t len) {
while(len > 0) { while(len > 0) {
chunk = (len > 3) ? 3 : len; chunk = (len > 3) ? 3 : len;
*out++ = base64table[(*data & 0xFC)>>2]; *out++ = base64table[(*data & 0xFC)>>2];
*out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
switch(chunk) { switch(chunk) {
case 3: case 3:
*out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
*out++ = base64table[((*(data+1) & 0x0F)<<2) | ((*(data+2) & 0xC0)>>6)]; *out++ = base64table[((*(data+1) & 0x0F)<<2) | ((*(data+2) & 0xC0)>>6)];
*out++ = base64table[(*(data+2)) & 0x3F]; *out++ = base64table[(*(data+2)) & 0x3F];
break; break;
case 2: case 2:
*out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
*out++ = base64table[((*(data+1) & 0x0F)<<2)]; *out++ = base64table[((*(data+1) & 0x0F)<<2)];
*out++ = '='; *out++ = '=';
break; break;
case 1: case 1:
*out++ = base64table[((*data & 0x03)<<4)];
*out++ = '='; *out++ = '=';
*out++ = '='; *out++ = '=';
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment