If you decode a string that doesn't have any padding characters, the final character is not returned.
Examples (from the review) 'Z2lhbmx1Y2E6YXNkYXNk' decodes as 'gianluca:asdas' but adding an unnecessary padding character (note any character I tried also worked, 'a', a carriage return, etc): 'Z2lhbmx1Y2E6YXNkYXNk=' decodes as 'gianluca:asdasd'
From Wikipedia (I added single quotes around the encoded text and decoded text for clarity)
'YW55IGNhcm5hbCBwbGVhcw==' Block with 2 '='s decodes to 1 character: 'any carnal pleas'
this decodes correctly
'YW55IGNhcm5hbCBwbGVhc3U=' Block with 1 '=' decodes to 2 characters: 'any carnal pleasu'
this decodes correctly
'YW55IGNhcm5hbCBwbGVhc3Vy' Block with 0 '='s decodes to 3 characters: 'any carnal pleasur'
this decodes as 'any carnal pleasu'
it seems that b64.c has wrong code at line 374.
putc() returns EOF if some error, so the line 374 should be like below.
if(putc((int)out[i],outfile)==EOF){
if(ferror()){
...
}
}
Thanks so much for the report. I am astonished that after all this time
there actually appears to be an honest to goodness bug in the code.
I will have to review the unit tests to see if I can somehow simulate this.
This would only become a problem if there is a write error. I did test
the code for write errors, but it was limited because it was hard to set
up. The way disk space is allocated I am not even sure if the error can be
created.
I receive bug reports from time to time but they are always because someone
has ripped out some of the code and are making an invalid call into one of
the functions.
Thanks again for making the report. I will review in the next couple of
days and if, as it appears, it is a bug, I will publish corrected code.
Cheers!
Bob Trower
On Mon, Mar 3, 2014 at 8:20 PM, Takashi Ando dodo5522@users.sf.net wrote:
Related
Bugs:
#6Code has been updated to version 0.94R and it has a small test added to ensure that binary code (the b64.exe file itself) is encoded and then decoded properly.
Many thanks to people who reviewed and reported this. It was very easy to find and fix things because of the reports showing exactly the symptom and even the offending lines of code.
Fixed Release 0.94R