Discussion:
[bug-mailutils] memory leak with mu_rfc2047_encode
Henrique Pantarotto
2017-02-16 15:15:17 UTC
Permalink
Hello friends!

One of my programs is presenting large memory usage, and I traced it down
to the mu_rfc2047_encode function that I'm using.

If you compile and run the program below, it will use all of your memory.

--start--
#include <stdio.h>
#include "mailutils/mailutils.h"

void main() {

char *value;

while(1) {
mu_rfc2047_encode("utf-8", "quoted-printable", "Any subject", &value);
printf("Result: %s\n", value);
if (value)
free(value);
}

}
--end--

I've tested this with the default "libmailutils-dev" (1:2.99.98-2) package
from Debian 8.7, but I've also tested with mailutils-3.1.1.

Perhaps I'm not using this function properly?

Thanks!
Sergey Poznyakoff
2017-02-17 07:36:15 UTC
Permalink
Hi Henrique,
Post by Henrique Pantarotto
One of my programs is presenting large memory usage, and I traced it down
to the mu_rfc2047_encode function that I'm using.
Thanks a lot for your report. I have fixed the bug in the repository.
Please apply this patch:

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=afaecb9b14696dfe12e2f2f501906dbd01cec27e

Best regards,
Sergey
Henrique Pantarotto
2017-02-17 12:35:52 UTC
Permalink
Hi Sergey!

Thank you so much for your quick reply and for the fix! I have tested and
it's working fine now!

I'm sorry that I didn't mention on the previous post, but there's also 2
"small" issues with this function. According to RFC 2047, the
'encoded-word' may not be more than 75 characters long, including
'charset', 'encoding', 'encoded-text', and delimiters (in this case, multiple
'encoded-word's --separated by CRLF SPACE-- may be used) . And the
'encoded-text' should not allow spaces and the '?' character. ('?' is
currently being used 'as is' but instead should be encoded as =3F).

If I encode the subject "Are you sure?" it will result as
"=?utf-8?Q?Are_you_sure??=" but should be "=?utf-8?Q?Are_you_sure=3F?=".
For curiosity, this only shows as en error with the Mail client from
Apple's iOS. All other mail readers that I've tested don't bother with this.

Another example:
"This is a really long subject line with a question mark at the end oh my
god it never ends?"

=?UTF-8?Q?This_is_a_really_long_subject_line_with_a_question_mark_at_the_e?=
<CRLF SPACE> =?UTF-8?Q?nd_oh_my_god_it_never_ends=3F?=

For a quick fix, I ended replacing this specific function with my own, but
I really want to thank you for taking your time to fix this so quickly.
You're amazing!

Thank you!

Regards from Brazil,
Henrique
Post by Sergey Poznyakoff
Hi Henrique,
Post by Henrique Pantarotto
One of my programs is presenting large memory usage, and I traced it down
to the mu_rfc2047_encode function that I'm using.
Thanks a lot for your report. I have fixed the bug in the repository.
http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=afaecb9b14696dfe12e2f2f501906dbd01cec27e
Best regards,
Sergey
Sergey Poznyakoff
2017-02-18 06:48:15 UTC
Permalink
Hi Henrique,
Post by Henrique Pantarotto
I'm sorry that I didn't mention on the previous post, but there's also 2
"small" issues with this function.
Thanks! These two are fixed in the following commit:

http://git.savannah.gnu.org/cgit/mailutils.git/commit/?id=480f7d0b369cc32ca30df6f10ed16c7308beab63

Best regards,
Sergey

Loading...