classification
Title: bytearray.extend does not handle errors during iteration.
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brandtbucher, miss-islington, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2019-06-26 18:21 by brandtbucher, last changed 2019-06-26 22:22 by brandtbucher. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 14407 merged brandtbucher, 2019-06-26 18:21
PR 14408 merged miss-islington, 2019-06-26 19:06
PR 14410 merged miss-islington, 2019-06-26 19:58
PR 14414 merged brandtbucher, 2019-06-26 22:22
Messages (4)
msg346655 - (view) Author: Brandt Bucher (brandtbucher) * (Python triager) Date: 2019-06-26 18:21
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. I've attached a patch with a fix and a regression test.
msg346664 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-06-26 19:06
New changeset 2a7d596f27b2342caf168a03c95ebf3b56e5dbbd by Serhiy Storchaka (Brandt Bucher) in branch 'master':
bpo-37417: Fix error handling in bytearray.extend. (GH-14407)
https://github.com/python/cpython/commit/2a7d596f27b2342caf168a03c95ebf3b56e5dbbd
msg346668 - (view) Author: miss-islington (miss-islington) Date: 2019-06-26 19:23
New changeset 7675bca4b56c532875d8bc6a7832e3c51d71278f by Miss Islington (bot) in branch '3.7':
bpo-37417: Fix error handling in bytearray.extend. (GH-14407)
https://github.com/python/cpython/commit/7675bca4b56c532875d8bc6a7832e3c51d71278f
msg346677 - (view) Author: miss-islington (miss-islington) Date: 2019-06-26 20:17
New changeset 5c4ce3e2fa73125fb6f9c501e6c4c8512216b7e1 by Miss Islington (bot) in branch '3.8':
bpo-37417: Fix error handling in bytearray.extend. (GH-14407)
https://github.com/python/cpython/commit/5c4ce3e2fa73125fb6f9c501e6c4c8512216b7e1
History
Date User Action Args
2019-06-26 22:22:41brandtbuchersetpull_requests: + pull_request14227
2019-06-26 20:17:31serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-06-26 20:17:03miss-islingtonsetmessages: + msg346677
2019-06-26 19:58:38miss-islingtonsetpull_requests: + pull_request14222
2019-06-26 19:23:24miss-islingtonsetnosy: + miss-islington
messages: + msg346668
2019-06-26 19:09:34SilentGhostsetversions: + Python 3.7, Python 3.8
2019-06-26 19:06:33miss-islingtonsetpull_requests: + pull_request14220
2019-06-26 19:06:31serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg346664
2019-06-26 18:21:17brandtbuchersetkeywords: + patch
stage: patch review
pull_requests: + pull_request14219
2019-06-26 18:21:02brandtbuchercreate