[Ace-users] [ace-bugs] Bug in ACE_Base64

Krishnakumar B kitty at dre.vanderbilt.edu
Sat Dec 15 12:15:27 CST 2007

Hi JT,

On Fri, 14 Dec 2007 11:33:07 PM -0600, J.T. Conklin wrote:
> Krishnakumar B <kitty at dre.vanderbilt.edu> writes:


> In a private response to my earlier message, Alick clarified his
> original complaint that some input "strings" were encoded with a
> trailing newline, while others were not.  From code inspection, 
> I found that the newline wasn't being added if the input string
> length was a multiple of 3.

Yes, that was the bug.

> It appears you chose to omit the final newline, while I chose to
> always emit it (in chunked mode).  An argument could be made for
> either choice, but I think emitting it makes more sense (I think
> the similar python and Java (in chunked mode) APIs emit a 
> newline too).

You are right.  It makes sense a lot more sense when you are creating a
MIME message since it relieve the clients from remembering to add a newline
at the end of the encoded output.

> Your patch changes length() and decode().  It's not obvious to me 
> what that fixes.  Perhaps whatever that addresses can be addressed
> separately?

Essentially the function ACE_Base64::decode() did three passes over the
input string (once to calculate the amount of memory to allocate, once to
calculate the length of the input string and once to actually do the
decoding).  I don't know what I was thinking when I wrote it :-)

So I think there are two way to fix it:

1. Make sure no one is using ACE_Base64::length() (it should have never
   been a public method) and if so, remove it and
   just put the loop inside ACE_Base64::decode() so that we only make two
   passes over the input.

2. Keep ACE_Base64::length() as it is, but change ACE_Base64::decode() so
   that we only make two passes over the input.

> Please share your thoughts,

Thanks a lot for your enhancement.  If you feel that the above paragraph is
a small addition to make (especially option 2) to your existing patch,
please add it along with your enhancement.


Krishnakumar B <kitty at dre dot vanderbilt dot edu>
Institute for Software Integrated Systems, Dept. of EECS, Vanderbilt University

More information about the Ace-users mailing list