Skip to content

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Jul 20, 2018

Now base64.Error is always raised instead of UnboundLocalError or
OverflowError.

https://bugs.python.org/issue34164

Now base64.Error is always raised instead of UnboundLocalError or
OverflowError.
Copy link
Member

@vstinner vstinner left a 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.

@serhiy-storchaka
Copy link
Member Author

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)]
Copy link
Member

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.

Copy link
Member Author

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?

@serhiy-storchaka serhiy-storchaka merged commit ac0b3c2 into python:master Jul 24, 2018
@miss-islington
Copy link
Contributor

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@serhiy-storchaka serhiy-storchaka deleted the base32-decode-padding branch July 24, 2018 09:52
@miss-islington
Copy link
Contributor

Sorry @serhiy-storchaka, I had trouble checking out the 3.6 backport branch.
Please backport using cherry_picker on command line.
cherry_picker ac0b3c2f4d86fc056b833a4e6b9a380741244a63 3.6

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 24, 2018
…ythonGH-8351)

Now base64.Error is always raised instead of UnboundLocalError or
OverflowError.
(cherry picked from commit ac0b3c2)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-bot
Copy link

GH-8435 is a backport of this pull request to the 3.7 branch.

serhiy-storchaka added a commit that referenced this pull request Jul 24, 2018
…H-8351) (GH-8435)

Now base64.Error is always raised instead of UnboundLocalError or
OverflowError.
(cherry picked from commit ac0b3c2)

Co-authored-by: Serhiy Storchaka <[email protected]>
serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this pull request Jul 24, 2018
…e(). (pythonGH-8351)

Now base64.Error is always raised instead of UnboundLocalError or
OverflowError.
(cherry picked from commit ac0b3c2)

Co-authored-by: Serhiy Storchaka <[email protected]>
@bedevere-bot
Copy link

GH-8436 is a backport of this pull request to the 3.6 branch.

serhiy-storchaka added a commit that referenced this pull request Jul 24, 2018
…e(). (GH-8351) (GH-8436)

Now base64.Error is always raised instead of UnboundLocalError or
OverflowError.
(cherry picked from commit ac0b3c2)

Co-authored-by: Serhiy Storchaka <[email protected]>
@serhiy-storchaka serhiy-storchaka removed their assignment Oct 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type-bug An unexpected behavior, bug, or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants