In message <[EMAIL PROTECTED]> on Mon, 20 Jun 2005 18:53:39 +0200, "Dr. Stephen 
Henson" <[EMAIL PROTECTED]> said:

steve> On Mon, Jun 20, 2005, Richard Levitte - VMS Whacker wrote:
steve> 
steve> > In message <[EMAIL PROTECTED]> on Mon, 20 Jun 2005 12:11:30 +0200, 
Beat Jucker <[EMAIL PROTECTED]> said:
steve> > 
steve> > bj> Given attached BASE64 encoded file openssl will write only 5280
steve> > bj> decoded bytes instead of the original 5305 bytes as other tools
steve> > bj> like mimencode, base64, Asn1Editor, web online base64 decoder, ...
steve> > bj> 
steve> > bj>   openssl base64 -d -in text.pem -out text.der
steve> > bj>   --> 5280 instead of 5305 bytes!?
steve> > 
steve> > I've played with previous incarnations, and noticed that with the
steve> > latest update for 0.9.7-stable, I get 5305 bytes, while I get 5280
steve> > bytes with 0.9.8-stable.  I compared crypto/evp/bio_b64.c from both
steve> > branches, and there is virtually no difference, so the problem is
steve> > somewhere else.
steve> > 
steve> > I noticed something unusual about your file: the lines are 76
steve> > characters, when a PEM file usually (or at least by default when
steve> > output by OpenSSL) has 64 character lines...  I have no clue how
steve> > important that fact is, but I'm going to conduct some tests.
steve> > 
steve> 
steve> The only significant change is:
steve> 
steve> http://cvs.openssl.org/chngview?cn=12988
steve> 
steve> whether this is the problem or it has just triggered a problem
steve> elsewhere I don't know.

This specific case seems to be because of the 76 character lines.  The
attached patch seems to fix it, though.

Really, the base64 decoder is quite the pile of crap.  Why on earth
does it have dependence on where a NL will appear?  There's absolutely
no reason unless you're a PEM fetishist...  It should really be
rewritten...

-----
Please consider sponsoring my work on free software.
See http://www.free.lp.se/sponsoring.html for details.

-- 
Richard Levitte                         [EMAIL PROTECTED]
                                        http://richard.levitte.org/

"When I became a man I put away childish things, including
 the fear of childishness and the desire to be very grown up."
                                                -- C.S. Lewis
Index: crypto/evp/encode.c
===================================================================
RCS file: /e/openssl/cvs/openssl/crypto/evp/encode.c,v
retrieving revision 1.14
diff -u -r1.14 encode.c
--- crypto/evp/encode.c 3 Apr 2005 16:38:22 -0000       1.14
+++ crypto/evp/encode.c 20 Jun 2005 22:01:26 -0000
@@ -313,7 +313,7 @@
                        /* There will never be more than two '=' */
                        }
 
-               if ((v == B64_EOF) || (n >= 64))
+               if ((v == B64_EOF && (n&3) == 0) || (n >= 64))
                        {
                        /* This is needed to work correctly on 64 byte input
                         * lines.  We process the line and then need to

Reply via email to