Re: MB_LEN_MAX has to be more than 5 if mutt uses UTF-8
* Wed Jul 16 2008 Paul Walker <paul@xxxxxxxxxxxxxxx>
> On Wed, Jul 16, 2008 at 02:34:06PM +0900, TAKAHASHI Tamotsu wrote:
>
> > + while (mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl) ==
> > (size_t)-1)
> [...]
> > + safe_realloc (&buf, len + obl + 1);
> > + }
>
> Is it possible to add some kind of limit condition on this? Call me
> paranoid, but I get nervous when I see reallocations in a loop with no clear
> limits on the amount of memory it will try to take.
>
> (Consider badly formed messages (deliberate or otherwise) and buggy iconv
> implementations.)
Good point.
Yes, MB_LEN_MAX*ibl works in most cases,
so it is "some kind of limit condition,"
though there is no limit _in theory_,
even with valid strings and settings.
The realloc loop is needed if either
(1) your MB_LEN_MAX is much less than enough or
(2) your locale or usage requires heavy N:M conversion.
Maybe i18n paranoids want to realloc, and
normal programmers don't.
I don't know which is right. ;)
It's okay to avoid the realloc loop (at least for me).
But I'd like the developers to know the limitation mutt has
that mutt truncates strings in some cases.
(So be careful when you use mutt_convert_string.
Even if a message is PGP-signed, it can be truncated.)
Well, adding dprint to mutt_iconv should be good then.
(e.g. if(iconv(...)==-1)dprint(3,(debugfile,"iconv failed:
%s\n",strerror(errno)));)
--
tamo
"And ulimit is always your friend."