[ python-Bugs-1170331 ] Error in base64.b32decode

SourceForge.net noreply at sourceforge.net
Thu Jun 9 00:54:47 CEST 2005


Bugs item #1170331, was opened at 2005-03-24 23:05
Message generated for change (Settings changed) made by akuchling
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1170331&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
>Category: Python Library
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: toidinamai (toidinamai)
>Assigned to: A.M. Kuchling (akuchling)
Summary: Error in base64.b32decode

Initial Comment:
Hi,                                                   
                                                      
                                                         
                                                      
                                                      
                                                         
I believe there is an error in base64.b32decode because
it doesn't seem to                                    
                                                          
allow to decode arbitrary binary data:                
                                                      
                                                         

<code>                                                
                                                      
                                                         
#!/usr/bin/env python2.4                              
                                                      
                                                         
                                                      
                                                      
                                                         
import base64                                         
                                                      
                                                         
                                                      
                                                      
                                                         
b64d = base64.b64decode                               
                                                      
                                                         
b64e = base64.b64encode                               
                                                      
                                                         
                                                      
                                                      
                                                         
print "base64: ", repr(b64d(b64e('\x00')))            
                                                      
                                                         
                                                      
                                                      
                                                         
b16d = base64.b16decode                               
                                                      
                                                         
b16e = base64.b16encode                               
                                                      
                                                         
                                                      
                                                      
                                                         
print "base16: ", repr(b16d(b16e('\x00')))            
                                                      
                                                         
                                                      
                                                      
                                                         
b32d = base64.b32decode                               
                                                      
                                                         
b32e = base64.b32encode                               
                                                      
                                                         
                                                      
                                                      
                                                         
print "base32: ", repr(b32d(b32e('\x00')))            
                                                      
                                                         
</code>                                               
                                                      
                                                         
                                                      
                                                      
                                                         
This raises a very strange exception:                 
                                                      
                                                         
                                                      
                                                      
                                                         
Traceback (most recent call last):                    
                                                      
                                                         
  File "test.py", line 18, in ?                       
                                                      
                                                         
    print "base32: ", repr(b32d(b32e('\x00')))        
                                                      
                                                         
  File "/usr/lib/python2.4/base64.py", line 228, in
b32decode                                             
                                                      
     
    last = binascii.unhexlify(hex(acc)[2:-1])         
                                                      
                                                         
TypeError: Odd-length string                          
                                                      
                                                         
                                                      
                                                      
                                                         
b32 should work just like b64 and b16.                
                                                      
                                                      
                                                      
                                                      
                                            

Best regards
Frank Bensktein.


----------------------------------------------------------------------

Comment By: A.M. Kuchling (akuchling)
Date: 2005-06-08 18:54

Message:
Logged In: YES 
user_id=11375

Fixed by applying patch #1171487, to both HEAD and 2.4-maint
branches.  Thanks for reporting this!


----------------------------------------------------------------------

Comment By: Terry J. Reedy (tjreedy)
Date: 2005-03-30 13:35

Message:
Logged In: YES 
user_id=593130

Your original report somehow got larded with blank lines that  
spread it over 4 screens.  If you can somehow prevent this next 
time, it would be much easier to read.

----------------------------------------------------------------------

Comment By: logistix (logistix)
Date: 2005-03-27 14:48

Message:
Logged In: YES 
user_id=699438

patch 1171487 posted.  It is pure python so you should be
able to incorporate into your existing codebase relatively
easily.  You won't need to rebuild the python executable.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1170331&group_id=5470


More information about the Python-bugs-list mailing list