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

Created on 2021-01-13 11:26 by tholl, last changed 2021-01-13 16:17 by miss-islington.

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 open miss-islington, 2021-01-13 16:17
PR 24212 open miss-islington, 2021-01-13 16:17
Messages (2)
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
History
Date User Action Args
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