[New-bugs-announce] [issue33770] base64 throws 'incorrect padding' exception even though the string length is a multiple of 4

Dmitry report at bugs.python.org
Mon Jun 4 15:53:31 EDT 2018


New submission from Dmitry <dniq at dniq-online.com>:

All base64 decoding methods fail to decode a valid base64 string, throwing 'incorrect padding' regardless of the string padding.

Here's an example:

>>> base64.urlsafe_b64decode('AQAAQDhAAMAAQAAAAAAAAthAAAAJDczODFmZDM2LTNiOTYtNDVmYS04MjQ2LWRkYzJkMmViYjQ2YQ===')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/export/apps/python/3.6/lib/python3.6/base64.py", line 133, in urlsafe_b64decode
    return b64decode(s)
  File "/export/apps/python/3.6/lib/python3.6/base64.py", line 87, in b64decode
    return binascii.a2b_base64(s)
binascii.Error: Incorrect padding

The same string gets decoded without any issues using Perl's MIME::Base64 module or Java. So far Python's base64 module is the only one that fails to decode it.

----------
components: Extension Modules
messages: 318691
nosy: dniq
priority: normal
severity: normal
status: open
title: base64 throws 'incorrect padding' exception even though the string length is a multiple of 4
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33770>
_______________________________________


More information about the New-bugs-announce mailing list