Hi,

I have been going through curl sources, and came across base64 encode and
decode implementation in lib/base64.c. I am not sure which workflow it will
hit, but the implementation seems wrong to me.

The encode function is implemented like this:

...
192   while(insize > 0) {
193     for (i = inputparts = 0; i < 3; i++) {
194       if(insize > 0) {
195         inputparts++;
196         ibuf[i] = *indata;
197         indata++;
198         insize--;
199       }
200       else
201         ibuf[i] = 0;
202     }
...

What happens is if my data is not a multiple of 3, line 193 causes problem

193     for (i = inputparts = 0; i < 3; i++) {

It tend to pick up noise from the end of the array and encode that also!
I think the check should be

193 for (i = inputparts = 0; i < 3 && insize > 0; i++) {

Thanks,
pc
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to