When converting binary values to Base 64 encoding, we go from a 8 bit
representation to a 6 bit representation. As a result, we need extra space
to store the result compared to the input value being converted.
In the current implementation, the requirements on the size of the output
buffer are too conservative; We only have to check if the remaining space
is larger than 4 (3 input bytes get converted into 4 Base64 encoded output
bytes, plus allowing for a terminating '\0' character) rather than 10.
---
base64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/base64.c b/base64.c
index 67e13c30..290f384e 100644
--- a/base64.c
+++ b/base64.c
@@ -60,7 +60,7 @@ void mutt_buffer_to_base64 (BUFFER *out, const unsigned char
*in, size_t len)
void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len,
size_t olen)
{
- while (len >= 3 && olen > 10)
+ while (len >= 3 && olen > 4)
{
*out++ = B64Chars[in[0] >> 2];
*out++ = B64Chars[((in[0] << 4) & 0x30) | (in[1] >> 4)];
--
2.25.3