Skip to content

bpo-37417: Fix error handling in bytearray.extend. #14407

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

Merged
merged 3 commits into from
Jun 26, 2019

Conversation

brandtbucher
Copy link
Member

@brandtbucher brandtbucher commented Jun 26, 2019

bytearray.extend doesn't properly handle errors that arise during iteration of the argument:

Python 3.9.0a0 (heads/master:5150d32, Jun 26 2019, 10:55:32) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> array = bytearray()
>>> bad_iter = map(int, "X")
>>> array.extend(bad_iter)
ValueError: invalid literal for int() with base 10: 'X'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SystemError: <method 'extend' of 'bytearray' objects> returned a result with an error set

As far as I can tell, this bug is present on all versions of Python 3. This patch adds a fix and a regression test.

https://bugs.python.org/issue37417

@serhiy-storchaka serhiy-storchaka added needs backport to 3.7 type-bug An unexpected behavior, bug, or error labels Jun 26, 2019
@serhiy-storchaka serhiy-storchaka merged commit 2a7d596 into python:master Jun 26, 2019
@miss-islington
Copy link
Contributor

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

@miss-islington
Copy link
Contributor

I'm having trouble backporting to 3.8. Reason: 'Error 110 while writing to socket. Connection timed out.'. Please retry by removing and re-adding the needs backport to 3.8 label.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 26, 2019
@bedevere-bot
Copy link

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

@brandtbucher
Copy link
Member Author

Thanks @serhiy-storchaka!

Just a heads-up, it looks like the 3.8 backport timed out...

@brandtbucher brandtbucher deleted the bytearray-extend branch June 26, 2019 19:14
miss-islington added a commit that referenced this pull request Jun 26, 2019
(cherry picked from commit 2a7d596)

Co-authored-by: Brandt Bucher <[email protected]>
@miss-islington
Copy link
Contributor

Thanks @brandtbucher for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 26, 2019
@bedevere-bot
Copy link

GH-14410 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this pull request Jun 26, 2019
(cherry picked from commit 2a7d596)

Co-authored-by: Brandt Bucher <[email protected]>
@serhiy-storchaka
Copy link
Member

Thank you for your contribution, @brandtbucher!

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