-
-
Notifications
You must be signed in to change notification settings - Fork 31.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-34164: Fix handling of incorrect padding in base64.b32decode(). #8351
bpo-34164: Fix handling of incorrect padding in base64.b32decode(). #8351
Conversation
Now base64.Error is always raised instead of UnboundLocalError or OverflowError.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I just have a minor suggestion.
What is your suggestion? |
Lib/base64.py
Outdated
decoded[-5:] = last[:-4] | ||
else: | ||
raise binascii.Error('Incorrect padding') | ||
decoded[-5:] = last[:-((padchars * 5 + 4) // 8)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover = (43 - 5 * padchars) // 8 # 1: 4, 3: 3, 4: 2, 6: 1
or
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