1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

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

This commit is contained in:
Philipp Schafft 2018-07-27 09:56:35 +00:00
parent 648947fe44
commit e900d8e80c

View File

@ -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;