[Pkg-mutt-maintainers] Bug#861235: mutt: Very large IMAP folders result in "could not copy message"

Paul Saunders darac at darac.org.uk
Wed Apr 26 11:23:00 UTC 2017


Package: mutt
Version: 1.7.2
Severity: normal
Tags: patch upstream

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Dear Maintainer,

For some reason, one of the mailboxes on my dovecot server has very
large UIDs (> 2**31). Trying to open messages with these very large UIDs
results in mutt complaining "Could not copy message" and failing to open
the message.

Upon investigation, I found that this is because mutt occasionally
treats UIDs as signed integers (the RFC states that they are, in fact,
unsigned ints). In the attached patch, I have tried to track down as
many instances of UIDs being treated as ints as I can (changing
declarations, replacing the use of atoi() with strtoul(), printing with
'%u' instead of '%d' and so on). This now means I can open messages in
the affected mailbox.


- -- Package-specific info:
NeoMutt 20170113 (1.7.2)
Copyright (C) 1996-2016 Michael R. Elkins and others.
Mutt comes with ABSOLUTELY NO WARRANTY; for details type `mutt -vv'.
Mutt is free software, and you are welcome to redistribute it
under certain conditions; type `mutt -vv' for details.

System: Linux 4.9.0-1-686-pae (i686)
libidn: 1.33 (compiled with 1.33)
hcache backends: tokyocabinet

Compiler:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/6/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 6.3.0-14' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=i686-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-i386/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-i386 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-i386 --with-arch-directory=i386 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-
 zlib --enable-objc-gc=auto --enable-targets=all --enable-multiarch --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 6.3.0 20170415 (Debian 6.3.0-14) 

Configure options: '--build=i686-linux-gnu' '--prefix=/usr' '--includedir=\${prefix}/include' '--mandir=\${prefix}/share/man' '--infodir=\${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-silent-rules' '--libdir=\${prefix}/lib/i386-linux-gnu' '--libexecdir=\${prefix}/lib/i386-linux-gnu' '--disable-maintainer-mode' '--disable-dependency-tracking' '--with-mailpath=/var/mail' '--enable-compressed' '--enable-debug' '--enable-fcntl' '--enable-hcache' '--enable-gpgme' '--enable-imap' '--enable-smtp' '--enable-pop' '--enable-sidebar' '--enable-nntp' '--enable-notmuch' '--disable-fmemopen' '--with-curses' '--with-gnutls' '--with-gss' '--with-idn' '--with-mixmaster' '--with-sasl' '--without-gdbm' '--without-bdb' '--without-qdbm' '--with-tokyocabinet' 'build_alias=i686-linux-gnu' 'CFLAGS=-g -O2 -fdebug-prefix-map=/usr/local/src/mutt-1.7.2=. -fstack-protector-strong -Wformat -Werror=format-security' 'LDFLAGS=-Wl,-z,relro -Wl,-z,now' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOU
 RCE=2'

Compilation CFLAGS: -Wall -pedantic -Wno-long-long -g -O2 -fdebug-prefix-map=/usr/local/src/mutt-1.7.2=. -fstack-protector-strong -Wformat -Werror=format-security -fno-delete-null-pointer-checks

Compile options:
+CRYPT_BACKEND_CLASSIC_PGP +CRYPT_BACKEND_CLASSIC_SMIME +CRYPT_BACKEND_GPGME 
+DEBUG +DL_STANDALONE +ENABLE_NLS -EXACT_ADDRESS -HOMESPOOL -LOCALES_HACK 
- -SUN_ATTACHMENT +HAVE_BKGDSET +HAVE_COLOR +HAVE_CURS_SET +HAVE_FUTIMENS 
+HAVE_GETADDRINFO +HAVE_GETSID +HAVE_ICONV +HAVE_LANGINFO_CODESET 
+HAVE_LANGINFO_YESEXPR +HAVE_LIBIDN +HAVE_META +HAVE_REGCOMP +HAVE_RESIZETERM 
+HAVE_START_COLOR +HAVE_TYPEAHEAD +HAVE_WC_FUNCS +ICONV_NONTRANS 
+USE_COMPRESSED +USE_DOTLOCK +USE_FCNTL -USE_FLOCK -USE_FMEMOPEN -USE_GNU_REGEX 
+USE_GSS +USE_HCACHE +USE_IMAP +USE_NOTMUCH +USE_NNTP +USE_POP +USE_SASL 
+USE_SETGID +USE_SIDEBAR +USE_SMTP +USE_SSL_GNUTLS -USE_SSL_OPENSSL 
- -DOMAIN
MIXMASTER="mixmaster"
ISPELL="/usr/bin/ispell"
SENDMAIL="/usr/sbin/sendmail"
MAILPATH="/var/mail"
PKGDATADIR="/usr/share/mutt"
SYSCONFDIR="/etc"
EXECSHELL="/bin/sh"

patch-attach-headers-color-neomutt
patch-compose-to-sender-neomutt
patch-compress-neomutt
patch-cond-date-neomutt
patch-encrypt-to-self-neomutt
patch-fmemopen-neomutt
patch-forgotten-attachments-neomutt
patch-forwref-neomutt
patch-ifdef-neomutt
patch-index-color-neomutt
patch-initials-neomutt
patch-keywords-neomutt
patch-kyoto-neomutt
patch-limit-current-thread-neomutt
patch-lmdb-neomutt
patch-multiple-fcc-neomutt
patch-nested-if-neomutt
patch-new-mail-neomutt
patch-nntp-neomutt
patch-notmuch-neomutt
patch-progress-neomutt
patch-quasi-delete-neomutt
patch-reply-with-xorig-neomutt
patch-sensible-browser-neomutt
patch-sidebar-neomutt
patch-skip-quoted-neomutt
patch-status-color-neomutt
patch-timeout-neomutt
patch-tls-sni-neomutt
patch-trash-neomutt

To learn more about NeoMutt, visit: http://www.neomutt.org/
If you find a bug in NeoMutt, please raise an issue at:
    https://github.com/neomutt/neomutt/issues
or send an email to: <neomutt-devel at neomutt.org>


- -- System Information:
Debian Release: 9.0
  APT prefers testing
  APT policy: (990, 'testing'), (500, 'unstable'), (1, 'experimental')
Architecture: i386
 (i686)

Kernel: Linux 4.9.0-1-686-pae (SMP w/1 CPU core)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages mutt depends on:
ii  libassuan0        2.4.3-2
ii  libc6             2.24-9
ii  libcomerr2        1.43.4-2
ii  libgnutls30       3.5.8-5
ii  libgpg-error0     1.26-2
ii  libgpgme11        1.8.0-3+b2
ii  libgssapi-krb5-2  1.15-1
ii  libidn11          1.33-1
ii  libk5crypto3      1.15-1
ii  libkrb5-3         1.15-1
ii  libncursesw5      6.0+20161126-1
ii  libnotmuch4       0.23.7-3
ii  libsasl2-2        2.1.27~101-g0780600+dfsg-3
ii  libtinfo5         6.0+20161126-1
ii  libtokyocabinet9  1.4.48-11+b1

Versions of packages mutt recommends:
ii  libsasl2-modules  2.1.27~101-g0780600+dfsg-3
ii  locales           2.24-9
ii  mime-support      3.60

Versions of packages mutt suggests:
ii  ca-certificates                 20161130
ii  gnupg                           2.1.18-6
ii  ispell                          3.4.00-5
pn  mixmaster                       <none>
ii  openssl                         1.1.0e-1
ii  postfix [mail-transport-agent]  3.1.4-4
ii  urlview                         0.9-20+b1

Versions of packages mutt is related to:
ii  mutt  1.7.2

- -- no debconf information

-----BEGIN PGP SIGNATURE-----

iQJHBAEBCgAxFiEE1A0c5XWknk+U2MemZUdBNabqRbUFAlkAgw0THGRhcmFjQGRh
cmFjLm9yZy51awAKCRBlR0E1pupFtX2XD/0QSkKv4JKO0/CgvD3Yd3B1Yd8zEeb5
IbWpanwoWIVRPFdh8zrC5HFNhA0cor5CTEFkYxDnwkUOjqxPMkpP99c69t9n28Jz
ecurdhCxAbaloxEaRs+/7/e4UOJ0JI4A0AWEviOwVfSwGOoxJ9fVieVUYfkeVM8i
sEl+KcUUihLlJez5U32vlbxWmACxQrNXWjDLKrsBwNIgFVBmZjYGPEq4udCHyvS5
0Cxv3ILyaxmhBVvbr6Zvz41w1MUAFTEOy6j/Mqy7jRux8j1iXWsEGtyd+6BgmZ88
hUcepvHzt5VDo5391M0y9cF5+NqnzKzY6+v/HNZrIOYatQch2OAR+z+SV6/mZ54v
3/DY//i3cZ4T32/8zbwmHeO9h+i1iMF4FIK8XSgAADxVra97IuKB5O6y8xsq5c0a
uU0LZKLF3zrvDxrIXiMTlc+gUwVNcTpQalyZVNBxCMIl3RLkYi6AZTgqhNdkh/fc
Zv1YLb0SZE6iYqdziAbdMF0Vq+H1c+8KyydzjzhqoceceWw1tgcfgs1Zs+zNmom6
y0VSwyBHWmoAFE4Trnrhg/q7GjPBzT1f4BeOPBGqzrXVIuclv9R4pqONqTRY8iY2
7F8ziVGY9r1poDPHKXZAZuxhrzcut54GQ+ZWd6/mz6z4cHg3gj0bIi622gsXzHWr
pW1UxkZmZMOmhA==
=Z6ml
-----END PGP SIGNATURE-----
-------------- next part --------------
diff --git a/mutt-1.7.2.orig/imap/command.c b/mutt-1.7.2/imap/command.c
index 7dde20f..c53269d 100644
--- a/mutt-1.7.2.orig/imap/command.c
+++ b/mutt-1.7.2/imap/command.c
@@ -636,7 +636,7 @@ static void cmd_parse_fetch (IMAP_DATA* idata, char* s)
       
       if (h && h->active && h->index+1 == msgno)
       {
-	dprint (2, (debugfile, "Message UID %d updated\n", HEADER_DATA(h)->uid));
+	dprint (2, (debugfile, "Message UID %u updated\n", HEADER_DATA(h)->uid));
 	break;
       }
       
@@ -883,7 +883,7 @@ static void cmd_parse_search (IMAP_DATA* idata, const char* s)
 
   while ((s = imap_next_word ((char*)s)) && *s != '\0')
   {
-    uid = atoi (s);
+    uid = strtoul (s, NULL, 10);
     msgno = uid2msgno (idata, uid);
     
     if (msgno >= 0)
@@ -899,7 +899,7 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
   char* value;
   BUFFY* inc;
   IMAP_MBOX mx;
-  int count;
+  unsigned int count;
   IMAP_STATUS *status;
   unsigned int olduv, oldun;
   long litlen;
@@ -941,7 +941,7 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
   while (*s && *s != ')')
   {
     value = imap_next_word (s);
-    count = strtol (value, &value, 10);
+    count = strtoul (value, &value, 10);
 
     if (!ascii_strncmp ("MESSAGES", s, 8))
     {
@@ -961,7 +961,7 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
     if (*s && *s != ')')
       s = imap_next_word (s);
   }
-  dprint (3, (debugfile, "%s (UIDVALIDITY: %d, UIDNEXT: %d) %d messages, %d recent, %d unseen\n",
+  dprint (3, (debugfile, "%s (UIDVALIDITY: %u, UIDNEXT: %u) %d messages, %d recent, %d unseen\n",
               status->name, status->uidvalidity, status->uidnext,
               status->messages, status->recent, status->unseen));
 
@@ -1000,7 +1000,7 @@ static void cmd_parse_status (IMAP_DATA* idata, char* s)
 
       if (value && !imap_mxcmp (mailbox, value))
       {
-        dprint (3, (debugfile, "Found %s in buffy list (OV: %d ON: %d U: %d)\n",
+        dprint (3, (debugfile, "Found %s in buffy list (OV: %u ON: %u U: %d)\n",
                     mailbox, olduv, oldun, status->unseen));
         
 	if (option(OPTMAILCHECKRECENT))
diff --git a/mutt-1.7.2.orig/imap/imap.c b/mutt-1.7.2/imap/imap.c
index 673e5e8..a007151 100644
--- a/mutt-1.7.2.orig/imap/imap.c
+++ b/mutt-1.7.2/imap/imap.c
@@ -261,7 +261,7 @@ void imap_expunge_mailbox (IMAP_DATA* idata)
 
     if (h->index == -1)
     {
-      dprint (2, (debugfile, "Expunging message UID %d.\n", HEADER_DATA (h)->uid));
+      dprint (2, (debugfile, "Expunging message UID %u.\n", HEADER_DATA (h)->uid));
 
       h->active = 0;
       idata->ctx->size -= h->content->length;
@@ -674,7 +674,7 @@ static int imap_open_mailbox (CONTEXT* ctx)
       dprint (3, (debugfile, "Getting mailbox UIDVALIDITY\n"));
       pc += 3;
       pc = imap_next_word (pc);
-      idata->uid_validity = strtol (pc, NULL, 10);
+      idata->uid_validity = strtoul (pc, NULL, 10);
       status->uidvalidity = idata->uid_validity;
     }
     else if (ascii_strncasecmp ("OK [UIDNEXT", pc, 11) == 0)
@@ -682,7 +682,7 @@ static int imap_open_mailbox (CONTEXT* ctx)
       dprint (3, (debugfile, "Getting mailbox UIDNEXT\n"));
       pc += 3;
       pc = imap_next_word (pc);
-      idata->uidnext = strtol (pc, NULL, 10);
+      idata->uidnext = strtoul (pc, NULL, 10);
       status->uidnext = idata->uidnext;
     }
     else
@@ -1681,7 +1681,7 @@ IMAP_STATUS* imap_mboxcache_get (IMAP_DATA* idata, const char* mbox, int create)
   if (hc)
   {
     uidvalidity = mutt_hcache_fetch_raw (hc, "/UIDVALIDITY", 12);
-    uidnext = mutt_hcache_fetch_raw (hc, "/UIDNEXT", 8);
+    uidnext = mutt_hcache_fetch_raw (hc, "/UIDNEXT", 12);
     if (uidvalidity)
     {
       if (!status)
diff --git a/mutt-1.7.2.orig/imap/message.c b/mutt-1.7.2/imap/message.c
index 75251af..a406226 100644
--- a/mutt-1.7.2.orig/imap/message.c
+++ b/mutt-1.7.2/imap/message.c
@@ -68,7 +68,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
   IMAP_STATUS* status;
   int rc, mfhrc, oldmsgcount;
   int fetchlast = 0;
-  int maxuid = 0;
+  unsigned int maxuid = 0;
   static const char * const want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL X-KEYWORDS X-MOZILLA-KEYS KEYWORDS X-ORIGINAL-TO";
   progress_t progress;
   int retval = -1;
@@ -125,7 +125,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
   if (idata->hcache && !msgbegin)
   {
     uid_validity = mutt_hcache_fetch_raw (idata->hcache, "/UIDVALIDITY", 12);
-    puidnext = mutt_hcache_fetch_raw (idata->hcache, "/UIDNEXT", 8);
+    puidnext = mutt_hcache_fetch_raw (idata->hcache, "/UIDNEXT", 12);
     if (puidnext)
     {
       uidnext = *(unsigned int *)puidnext;
@@ -368,7 +368,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend)
     idata->uidnext = maxuid + 1;
   }
   if (idata->uidnext > 1)
-    mutt_hcache_store_raw (idata->hcache, "/UIDNEXT", 8,
+    mutt_hcache_store_raw (idata->hcache, "/UIDNEXT", 12,
             &idata->uidnext, sizeof (idata->uidnext));
 
   imap_hcache_close (idata);
@@ -403,8 +403,8 @@ int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
   char *pc;
   long bytes;
   progress_t progressbar, *pbar;
-  int uid;
-  int cacheno;
+  unsigned int uid;
+  unsigned int cacheno;
   IMAP_CACHE *cache;
   int read;
   int rc;
@@ -444,6 +444,7 @@ int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
 
   if (!isendwin())
     mutt_message _("Fetching message...");
+  dprint(1, (debugfile, "Fetching msgno %d, UID: %u...\n", msgno, HEADER_DATA(h)->uid));
 
   if (!(msg->fp = msg_cache_put (idata, h)))
   {
@@ -487,7 +488,7 @@ int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno)
 	if (ascii_strncasecmp ("UID", pc, 3) == 0)
 	{
 	  pc = imap_next_word (pc);
-	  uid = atoi (pc);
+	  uid = strtoul (pc, NULL, 10);
 	  if (uid != HEADER_DATA(h)->uid)
 	    mutt_error (_("The message index is incorrect. Try reopening the mailbox."));
 	}
@@ -1121,7 +1122,7 @@ static int msg_fetch_header (CONTEXT* ctx, IMAP_HEADER* h, char* buf, FILE* fp)
 
   /* skip to message number */
   buf = imap_next_word (buf);
-  h->sid = atoi (buf);
+  h->sid = strtoul (buf, NULL, 10);
 
   /* find FETCH tag */
   buf = imap_next_word (buf);
@@ -1184,7 +1185,7 @@ static int msg_parse_fetch (IMAP_HEADER *h, char *s)
     {
       s += 3;
       SKIPWS (s);
-      h->data->uid = (unsigned int) atoi (s);
+      h->data->uid = (unsigned int) strtoul (s, NULL, 10);
 
       s = imap_next_word (s);
     }


More information about the Pkg-mutt-maintainers mailing list