[prev in list] [next in list] [prev in thread] [next in thread] List: cyrus-info Subject: Re: Excessive APPENDLIMIT response [Re: Android after Cyrus upgrade] From: Sebastian Hagedorn <Hagedorn () uni-koeln ! de> Date: 2023-05-16 17:55:08 Message-ID: 19E6482B-7A1C-4CC1-B4B8-AFB29C1AD1C2 () uni-koeln ! de [Download RAW message or body] [Attachment #2 (multipart/signed)] [Attachment #4 (multipart/alternative)] On 15 May 2023, at 2:46, ellie timoney wrote: > On Fri, 12 May 2023, at 11:50 PM, Sebastian Hagedorn wrote: > > On 12 May 2023, at 7:15, Vladas Palubinskas via Info wrote: > > > > > Thank you for the very clear explanation, but then I do not quite catch why the \ > > > reverse happened: why FairEmail got my limit backwards — why maxmessagesize: \ > > > 2097152 in imapd.conf acted as refused infinity, and almost infinite \ > > > maxmessagesize: false accepted as a reasonable default value. > > I can confirm that *setting* maxmessagesize to something leads to the "unlimited" \ > > value in 3.6.1. > > Without maxmessagesize in imapd.conf: > > > > APPENDLIMIT=4294967295 > > > > With maxmessagesize: 52428800 in imapd.conf: > > > > APPENDLIMIT=18446744071562067968 > > > > That isn't actually the "unlimited" value, which is weird... > > Ahh... in 3.6 (and probably earlier), maxmessagesize is interpreted as *bytes* by \ > LMTP, but as *kilobytes* by APPEND. Which means your "maxmessagesize: 52428800" is \ > ~50MB by LMTP, but ~50GB by APPEND. I think this bug has existed for a while, and \ > the new APPENDLIMIT output is just making it visible now. > When APPEND misinterprets it as kilobytes, it multiplies it by 1024 to "convert it" \ > to bytes. It does that multiplication in 32 bits, which overflows to negative \ > probably, but then stores the result in a size_t, which treats it as a massive \ > positive value. > This happens around line 911 of imap/imapd.c in service_init(): > > maxsize = config_getint(IMAPOPT_MAXMESSAGESIZE) * 1024; > if (!maxsize) maxsize = UINT32_MAX; > > Without actually having tested anything yet, I think if you just remove that * 1024 \ > and recompile/reinstall/restart, it'll start behaving. That is, make these lines \ > say: > maxsize = config_getint(IMAPOPT_MAXMESSAGESIZE); > if (!maxsize) maxsize = UINT32_MAX; > > I'll get a proper, tested, fix for this together soon. Tracking this on GitHub as \ > https://github.com/cyrusimap/cyrus-imapd/issues/4506 Thanks, that works! Cheers, Sebastian -- .:.Sebastian Hagedorn - Weyertal 121 (Gebäude 133), Zimmer 2.13.:. .:.Regionales Rechenzentrum (RRZK).:. .:.Universität zu Köln / Cologne University - ✆ +49-221-470-89578.:. [Attachment #7 (text/html)] <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8"> </head> <body><div style="font-family: sans-serif;"><div class="plaintext" \ style="white-space: normal;"><p dir="auto">On 15 May 2023, at 2:46, ellie timoney \ wrote:</p> <blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px \ solid #777777; color: #777777;"><p dir="auto">On Fri, 12 May 2023, at 11:50 PM, \ Sebastian Hagedorn wrote:</p> <blockquote style="margin: 0 0 5px; padding-left: 5px; \ border-left: 2px solid #777777; border-left-color: #999999; color: #999999;"><p \ dir="auto">On 12 May 2023, at 7:15, Vladas Palubinskas via Info wrote:</p> \ <blockquote style="margin: 0 0 5px; padding-left: 5px; border-left: 2px solid \ #777777; border-left-color: #BBBBBB; color: #BBBBBB;"><p dir="auto">Thank you for the \ very clear explanation, but then I do not quite catch why the reverse happened: why \ FairEmail got my limit backwards — why maxmessagesize: 2097152 in imapd.conf acted \ as refused infinity, and almost infinite maxmessagesize: false accepted as a \ reasonable default value.</p> </blockquote><p dir="auto">I can confirm that *setting* \ maxmessagesize to something leads to the "unlimited" value in 3.6.1.</p> <p \ dir="auto">Without maxmessagesize in imapd.conf:</p> <p \ dir="auto">APPENDLIMIT=4294967295</p> <p dir="auto">With maxmessagesize: 52428800 in \ imapd.conf:</p> <p dir="auto">APPENDLIMIT=18446744071562067968</p> </blockquote><p dir="auto">That isn't actually the "unlimited" value, which is \ weird...</p> <p dir="auto">Ahh... in 3.6 (and probably earlier), maxmessagesize is \ interpreted as *bytes* by LMTP, but as *kilobytes* by APPEND. Which means your \ "maxmessagesize: 52428800" is ~50MB by LMTP, but ~50GB by APPEND. I think this bug \ has existed for a while, and the new APPENDLIMIT output is just making it visible \ now.</p> <p dir="auto">When APPEND misinterprets it as kilobytes, it multiplies it by \ 1024 to "convert it" to bytes. It does that multiplication in 32 bits, which \ overflows to negative probably, but then stores the result in a size_t, which treats \ it as a massive positive value.</p> <p dir="auto">This happens around line 911 of \ imap/imapd.c in service_init():</p> <p dir="auto"> maxsize = \ config_getint(IMAPOPT_MAXMESSAGESIZE) * 1024; <br> if (!maxsize) maxsize = UINT32_MAX;</p> <p dir="auto">Without actually having tested anything yet, I think if you just remove \ that * 1024 and recompile/reinstall/restart, it'll start behaving. That is, make \ these lines say:</p> <p dir="auto"> maxsize = \ config_getint(IMAPOPT_MAXMESSAGESIZE); <br> if (!maxsize) maxsize = UINT32_MAX;</p> <p dir="auto">I'll get a proper, tested, fix for this together soon. Tracking this \ on GitHub as <a href="https://github.com/cyrusimap/cyrus-imapd/issues/4506" \ style="color: #777777;">https://github.com/cyrusimap/cyrus-imapd/issues/4506</a></p> \ </blockquote><p dir="auto">Thanks, that works!</p> <p dir="auto">Cheers, <br> Sebastian <br> -- <br> .:.Sebastian Hagedorn - Weyertal 121 (Gebäude 133), Zimmer 2.13.:. <br> .:.Regionales Rechenzentrum (RRZK).:. <br> .:.Universität zu Köln / Cologne University - ✆ +49-221-470-89578.:.</p> </div> </div> </body> </html> ["smime.p7s" (smime.p7s)] 0 *H 010 `He 0 *H 00 %ف0 *H 010 UDE1+0)U "T-Systems Enterprise Services GmbH10UT-Systems Trust \ Center1%0#UT-TeleSec GlobalRoot Class 20 160222133822Z 310222235959Z010 UDE1E0CU <Verein zur Foerderung eines Deutschen Forschungsnetzes e. \ V.10UDFN-PKI1-0+U$DFN-Verein Certification Authority 20"0 *H 0 `fAsMg9Z`GNWKVlUvFEc>pԫT#7( ]Ę7 \ fx J2)y T_Jx4twMYZ/l<