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) {
while(len > 0) {
chunk = (len > 3) ? 3 : len;
*out++ = base64table[(*data & 0xFC)>>2];
*out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
switch(chunk) {
case 3:
*out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
*out++ = base64table[((*(data+1) & 0x0F)<<2) | ((*(data+2) & 0xC0)>>6)];
*out++ = base64table[(*(data+2)) & 0x3F];
break;
case 2:
*out++ = base64table[((*data & 0x03)<<4) | ((*(data+1) & 0xF0) >> 4)];
*out++ = base64table[((*(data+1) & 0x0F)<<2)];
*out++ = '=';
break;
case 1:
*out++ = base64table[((*data & 0x03)<<4)];
*out++ = '=';
*out++ = '=';
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