This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: base64.b32decode() leads into UnboundLocalError and OverflowError on some data
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Barro, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-07-20 09:21 by Barro, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 8351 merged serhiy.storchaka, 2018-07-20 15:09
PR 8435 merged miss-islington, 2018-07-24 09:53
PR 8436 merged serhiy.storchaka, 2018-07-24 10:55
Messages (6)
msg321991 - (view) Author: Jussi Judin (Barro) Date: 2018-07-20 09:21
base64.b32decode() function leads into "UnboundLocalError: local variable 'acc' referenced before assignment" when passing 8 equality signs as data:

>>> import base64
>>> base64.b32decode(b"========")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/python-3.7-bin/lib/python3.7/base64.py", line 235, in b32decode
    acc <<= 5 * padchars
UnboundLocalError: local variable 'acc' referenced before assignment

When passing a different number of equality signs, the documented binascii.Error exception is thrown.
msg321992 - (view) Author: Jussi Judin (Barro) Date: 2018-07-20 09:28
Apparently base64.b32decode() also has another issue that I missed when going through the issues with base64 module:

>>> import base64
>>> base64.b32decode(b"M===============================")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/python-3.7-bin/lib/python3.7/base64.py", line 236, in b32decode
    last = acc.to_bytes(5, 'big')
OverflowError: int too big to convert
msg322012 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-20 15:13
Thank you for your report Jussi.

The type "crash" is used for hard crashes of the Python interpreter – possibly with a core dump or a Windows error box.
msg322284 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-24 09:52
New changeset ac0b3c2f4d86fc056b833a4e6b9a380741244a63 by Serhiy Storchaka in branch 'master':
bpo-34164: Fix handling of incorrect padding in base64.b32decode(). (GH-8351)
https://github.com/python/cpython/commit/ac0b3c2f4d86fc056b833a4e6b9a380741244a63
msg322289 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-24 10:53
New changeset 0b2716918345b2bff0bb5c36086d5de368125536 by Serhiy Storchaka (Miss Islington (bot)) in branch '3.7':
bpo-34164: Fix handling of incorrect padding in base64.b32decode(). (GH-8351) (GH-8435)
https://github.com/python/cpython/commit/0b2716918345b2bff0bb5c36086d5de368125536
msg322294 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-07-24 12:07
New changeset 113f86e7487e9312a2494667b088854ac942ab00 by Serhiy Storchaka in branch '3.6':
[3.6] bpo-34164: Fix handling of incorrect padding in base64.b32decode(). (GH-8351) (GH-8436)
https://github.com/python/cpython/commit/113f86e7487e9312a2494667b088854ac942ab00
History
Date User Action Args
2022-04-11 14:59:03adminsetgithub: 78345
2018-07-24 12:12:19serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-07-24 12:07:01serhiy.storchakasetmessages: + msg322294
2018-07-24 10:55:37serhiy.storchakasetpull_requests: + pull_request7961
2018-07-24 10:53:45serhiy.storchakasetmessages: + msg322289
2018-07-24 09:53:11miss-islingtonsetpull_requests: + pull_request7960
2018-07-24 09:52:59serhiy.storchakasetmessages: + msg322284
2018-07-20 15:13:28serhiy.storchakasetversions: + Python 3.6, Python 3.8
nosy: + serhiy.storchaka

messages: + msg322012

type: crash -> behavior
2018-07-20 15:09:25serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request7886
2018-07-20 09:28:43Barrosetmessages: + msg321992
title: base64.b32decode() leads into UnboundLocalError on some data -> base64.b32decode() leads into UnboundLocalError and OverflowError on some data
2018-07-20 09:21:09Barrocreate