Discuss general web development related issues. For Opera bugs, use the Bug Report Wizard: https://bugs.opera.com/wizard/. For Opera feature requests and queries, use Desktop wish-list: http://my.opera.com/community/forums/forum.dml?id=24.
By ubergeek42
Sunday, 5. July 2009, 04:31:51

Bug in Base64 Library
I'm not really sure where to post this, so please move this if it is in the wrong place.
The Base64 encoder (found at
http://dev.opera.com/libraries/base64encoder/) contains a bug that results in nearly all encoded strings to be incorrect. The bug is that if a string has to be padded with equal signs, it is also padded with 'A's before those equal signs, due to the construction of the out string not ignoring bytes that were added on for padding.
This may be easier for me to just show you what I mean(Examples taken from Wikipedia):
base64("leasure.") = "bGVhc3VyZS4=", but this library returns "bGVhc3VyZS4
A="
base64("easure.") = "ZWFzdXJlLg==", but this library returns "ZWFzdXJlLg
AA=="
Note the extra A's at the end before the equal signs.
I am not concerned with this bug very much(I wrote my own Base64 Encoder/Decoder before realizing this existed), but I figured I would report this issue.(Also the code is from 2006, so I doubt it gets much use...)
By sigbjornfinne
Monday, 6. July 2009, 06:40:51

Originally posted by ubergeek42:
...
I am not concerned with this bug very much(I wrote my own Base64 Encoder/Decoder before realizing this existed), but I figured I would report this issue.(Also the code is from 2006, so I doubt it gets much use...)
Many thanks for the heads up & report though

base64 decoders may do the right thing and strip these excessive pad zeroes
(=> 'A's in the output), but relying on that is probably best avoided.
For that given formulation of an encoder, the simplest fix is to simply
chop off the zero pad bytes -- i.e., in
convertStringToBase64(), instead of
return out+endBytes;do
if ( endBytes != '' ) {
return (out.slice(0,out.length-endBytes.length)+endBytes);
} else {
return out;
}
By ubergeek42
Monday, 6. July 2009, 16:08:50

Originally posted by sigbjornfinne:
base64 decoders may do the right thing and strip these excessive pad zeroes
(=> 'A's in the output), but relying on that is probably best avoided.
Thanks for the reply and the info on this, I basically got all of my base64 knowledge from wikipedia, and even then I only skimmed enough to make my code work like their examples. I will keep this in mind and possibly modify my base64 decoder to deal with other encoders that may not strip off these bytes.