]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: istream-base64-encoder - Fix getting size for empty stream
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 31 Oct 2017 15:42:15 +0000 (17:42 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 31 Oct 2017 15:42:15 +0000 (17:42 +0200)
src/lib/istream-base64-encoder.c
src/lib/test-istream-base64-encoder.c

index c1ae2bb2ce561b9998f4da6a3ed2432f86cb2072..c51fdcda1ccba6598c3f12263d414f28e74e8118 100644 (file)
@@ -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 +
index e03effa354824beb8d5ffe7ed93194560459e019..8f9f2fa3b8e4af2e1835834662edd7a99d37b201 100644 (file)
@@ -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=" },