#3558: A bug in a debugging output of handler.c
--------------------+-------------------------------------------------------
 Reporter:  hhorak  |       Owner:  mutt-dev
     Type:  defect  |      Status:  new     
 Priority:  minor   |   Milestone:          
Component:  mutt    |     Version:  1.5.21  
 Keywords:          |  
--------------------+-------------------------------------------------------
 This issue has been originally reported by Michal Jaegermann:
 https://bugzilla.redhat.com/770892

 With debugging code turned on mutt may get sometimes bogus messages when
 saving base64 encoded attachments.  Like that:

 handler.c:310 [mutt_decode_base64()]: didn't get a multiple of 4 chars.

 This is from this code:

 {{{
   while (len > 0)
   {
     for (i = 0 ; i < 4 && len > 0 ; len--)
     {
       if ((ch = fgetc (s->fpin)) == EOF)
         break;
       if (ch >= 0 && ch < 128 && (base64val(ch) != -1 || ch == '='))
         buf[i++] = ch;
     }
     if (i != 4)
     {
       dprint (2, (debugfile, "%s:%d [mutt_decode_base64()]: "
                   "didn't get a multiple of 4 chars.\n", __FILE__,
 __LINE__));
       break;
     }
 ......
   }
 }}}

 and a message may be bogus because it will happen also when i is 0 - which
 is definitely a multiple of 4 and means that we just finished decoding.

 That does happen in "real life" but it is easy to construct simple demo
 example.

 Just put into an attachment results of 'echo -n abc | base64', which comes
 to YWJj, followed by a new line.  Then the second run of 'while' loop
 starts with len set to 1, nothing is put in buf so i ends as 0 and 4*0 is
 deemed not to be a multiple of 4. :-)

 To fix simply add 'i == 0 && break;' before "dprint" line.

-- 
Ticket URL: <http://dev.mutt.org/trac/ticket/3558>
Mutt <http://www.mutt.org/>
The Mutt mail user agent

Reply via email to