[New-bugs-announce] [issue42924] bytearray_repeat copies from ob_bytes instead of ob_start

tholl report at bugs.python.org
Wed Jan 13 06:26:55 EST 2021

New submission from tholl <py at any.tholl.xyz>:

`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)
>>> print(ba * 1)

I'll try to submit a PR for this later today.

components: Interpreter Core
files: poc.py
messages: 385017
nosy: tholl
priority: normal
severity: normal
status: open
title: bytearray_repeat copies from ob_bytes instead of ob_start
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49739/poc.py

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list