Skip to content

Commit

Permalink
lib: istream-base64-encoder - Fix getting size for empty stream
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Oct 31, 2017
1 parent f134770 commit b9b86a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/lib/istream-base64-encoder.c
Expand Up @@ -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 +
Expand Down
6 changes: 6 additions & 0 deletions src/lib/test-istream-base64-encoder.c
Expand Up @@ -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=" },
Expand Down

0 comments on commit b9b86a2

Please sign in to comment.