This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: bytearray_repeat copies from ob_bytes instead of ob_start
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: lukasz.langa, miss-islington, python-dev, serhiy.storchaka, tholl
Priority: normal Keywords: patch

Created on 2021-01-13 11:26 by tholl, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
poc.py tholl, 2021-01-13 11:26 Minimal example to reproduce this issue
Pull Requests
URL Status Linked Edit
PR 24208 merged python-dev, 2021-01-13 13:15
PR 24211 merged miss-islington, 2021-01-13 16:17
PR 24212 merged miss-islington, 2021-01-13 16:17
Messages (4)
msg385017 - (view) Author: (tholl) * Date: 2021-01-13 11:26
`bytearray_repeat` uses `ob_bytes` rather than `ob_start` as its source data for copying, leading to incorrect results in some edge cases where the two are distinct. It should probably use `PyByteArray_AS_STRING(self)` just like `bytearray_irepeat` and basically all the other functions.

As far as I can see, these edge cases occur pretty much only after `bytearray_setslice_linear`, where `ob_start` can be adjusted without changing `ob_bytes`. 

A simple example (also attached as poc.py):

>>> ba = bytearray(b'0123456789abcdef')
>>> ba[:10] = b'test'
>>> print(ba)
bytearray(b'testabcdef')
>>> print(ba * 1)
bytearray(b'012345test')

I'll try to submit a PR for this later today.
msg385046 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-01-13 16:17
New changeset 61d8c54f43a7871d016f98b38f86858817d927d5 by Tobias Holl in branch 'master':
bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208)
https://github.com/python/cpython/commit/61d8c54f43a7871d016f98b38f86858817d927d5
msg391977 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-04-26 19:40
New changeset d0698c676ca1b7d34be4165a631bf4847583de76 by Miss Islington (bot) in branch '3.9':
bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208) (#24211)
https://github.com/python/cpython/commit/d0698c676ca1b7d34be4165a631bf4847583de76
msg391978 - (view) Author: Łukasz Langa (lukasz.langa) * (Python committer) Date: 2021-04-26 19:40
New changeset e1203e8001432a08b87b54867490beb19a694069 by Miss Islington (bot) in branch '3.8':
bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208) (#24212)
https://github.com/python/cpython/commit/e1203e8001432a08b87b54867490beb19a694069
History
Date User Action Args
2022-04-11 14:59:40adminsetgithub: 87090
2021-04-26 19:41:18lukasz.langasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-04-26 19:40:47lukasz.langasetmessages: + msg391978
2021-04-26 19:40:00lukasz.langasetnosy: + lukasz.langa
messages: + msg391977
2021-01-13 16:17:29miss-islingtonsetpull_requests: + pull_request23039
2021-01-13 16:17:19miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request23038
2021-01-13 16:17:03serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg385046
2021-01-13 13:37:25thollsettype: behavior
2021-01-13 13:15:28python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request23035
stage: patch review
2021-01-13 11:26:55thollcreate