From: Timo Sirainen Date: Tue, 31 Oct 2017 15:42:15 +0000 (+0200) Subject: lib: istream-base64-encoder - Fix getting size for empty stream X-Git-Tag: 2.3.0.rc1~673 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9b86a27aaf998e7024ec159f670cdc30c755d64;p=thirdparty%2Fdovecot%2Fcore.git lib: istream-base64-encoder - Fix getting size for empty stream --- 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=" },