From b9b86a27aaf998e7024ec159f670cdc30c755d64 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 31 Oct 2017 17:42:15 +0200 Subject: [PATCH] lib: istream-base64-encoder - Fix getting size for empty stream --- src/lib/istream-base64-encoder.c | 2 ++ src/lib/test-istream-base64-encoder.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/lib/istream-base64-encoder.c b/src/lib/istream-base64-encoder.c index c1ae2bb2ce..c51fdcda1c 100644 --- a/src/lib/istream-base64-encoder.c +++ b/src/lib/istream-base64-encoder.c @@ -158,6 +158,8 @@ i_stream_base64_encoder_stat(struct istream_private *stream, } stream->statbuf = *st; + if (st->st_size == 0) + return 0; /* calculate size of encoded data */ size = (st->st_size / 3) * 4 + diff --git a/src/lib/test-istream-base64-encoder.c b/src/lib/test-istream-base64-encoder.c index e03effa354..8f9f2fa3b8 100644 --- a/src/lib/test-istream-base64-encoder.c +++ b/src/lib/test-istream-base64-encoder.c @@ -11,6 +11,12 @@ static const struct test { bool crlf; const char *output; } tests[] = { + { "", 80, FALSE, "" }, + { "1", 80, FALSE, "MQ==" }, + { "12", 80, FALSE, "MTI=" }, + { "123", 80, FALSE, "MTIz" }, + { "1234", 80, FALSE, "MTIzNA==" }, + { "12345", 80, FALSE, "MTIzNDU=" }, { "hello world", 80, FALSE, "aGVsbG8gd29ybGQ=" }, { "hello world", 4, FALSE, "aGVs\nbG8g\nd29y\nbGQ=" }, { "hello world", 4, TRUE, "aGVs\r\nbG8g\r\nd29y\r\nbGQ=" },