From 7a7c4b49d33afad37ed3634f5167b8af60716423 Mon Sep 17 00:00:00 2001 From: Andrey Skvortsov Date: Thu, 21 Feb 2019 16:37:05 +0300 Subject: [PATCH] Fix truncation of long filenames in attachments Currently mutt truncates long filenames in attachments and doesn't take into account UTF-8 character size. If filename is truncated in the middle of multi-byte UTF-8 character (last character is bad), then some mail clients assume whole attachment name bad and don't display its name (use 'Noname' instead). Filenames can be up to 255 *characters* long depending on used filesystem. ReiserFS, NFTS, FAT, APFS and some other supports up to 255 characters. In the worst case 255 characters in UTF-8 will take 255*4 = 1020 bytes. Every non-ascii byte in the filename will be encoded using 3 bytes (for example, %8D). So 'Content-Disposition' will take in the worst case up to: 1020*3 = 3060 bytes. Therefore even LONG_STRING (1024) isn't enough. Co-authored-by: Richard Russon --- sendlib.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sendlib.c b/sendlib.c index 752ef940a..a7ba320fa 100644 --- a/sendlib.c +++ b/sendlib.c @@ -371,8 +371,7 @@ int mutt_write_mime_header(struct Body *a, FILE *fp) fputc(';', fp); - char buf[256]; - buf[0] = '\0'; + char buf[8192] = { 0 }; tmp = mutt_str_strdup(np->value); const int encode = rfc2231_encode_string(&tmp); mutt_addr_cat(buf, sizeof(buf), tmp, MimeSpecials); -- 2.40.0