bpo-34164: Fix handling of incorrect padding in base64.b32decode().#8351
Conversation
Now base64.Error is always raised instead of UnboundLocalError or OverflowError.
vstinner
left a comment
There was a problem hiding this comment.
LGTM. I just have a minor suggestion.
|
What is your suggestion? |
| decoded[-5:] = last[:-4] | ||
| else: | ||
| raise binascii.Error('Incorrect padding') | ||
| decoded[-5:] = last[:-((padchars * 5 + 4) // 8)] |
There was a problem hiding this comment.
I would suggest to put the complex operation a a separated line. Example:
n = ((padchars * 5 + 4) // 8)
decoded[-5:] = last[:-n]
Oh, GitHub lost my comment. I had to write it again.
There was a problem hiding this comment.
leftover = (43 - 5 * padchars) // 8 # 1: 4, 3: 3, 4: 2, 6: 1or
leftover = (5, 4, 4, 3, 2, 2, 1, 1, 0)[padchars]or
leftover = (..., 4, ..., 3, 2, ..., 1)[padchars]What is better?
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
|
Sorry @serhiy-storchaka, I had trouble checking out the |
…ythonGH-8351) Now base64.Error is always raised instead of UnboundLocalError or OverflowError. (cherry picked from commit ac0b3c2) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
GH-8435 is a backport of this pull request to the 3.7 branch. |
…e(). (pythonGH-8351) Now base64.Error is always raised instead of UnboundLocalError or OverflowError. (cherry picked from commit ac0b3c2) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
|
GH-8436 is a backport of this pull request to the 3.6 branch. |
Now base64.Error is always raised instead of UnboundLocalError or
OverflowError.
https://bugs.python.org/issue34164