Skip to content
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

bytearray_repeat copies from ob_bytes instead of ob_start #87090

Closed
TobiasHoll mannequin opened this issue Jan 13, 2021 · 4 comments
Closed

bytearray_repeat copies from ob_bytes instead of ob_start #87090

TobiasHoll mannequin opened this issue Jan 13, 2021 · 4 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@TobiasHoll
Copy link
Mannequin

TobiasHoll mannequin commented Jan 13, 2021

BPO 42924
Nosy @ambv, @serhiy-storchaka, @miss-islington, @TobiasHoll
PRs
  • bpo-42924: Fix incorrect copy in bytearray_repeat #24208
  • [3.9] bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208) #24211
  • [3.8] bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208) #24212
  • Files
  • poc.py: Minimal example to reproduce this issue
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-04-26.19:41:18.042>
    created_at = <Date 2021-01-13.11:26:55.556>
    labels = ['interpreter-core', 'type-bug', '3.8', '3.9', '3.10', '3.7']
    title = 'bytearray_repeat copies from ob_bytes instead of ob_start'
    updated_at = <Date 2021-04-26.19:41:18.042>
    user = 'https://github.com/TobiasHoll'

    bugs.python.org fields:

    activity = <Date 2021-04-26.19:41:18.042>
    actor = 'lukasz.langa'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-26.19:41:18.042>
    closer = 'lukasz.langa'
    components = ['Interpreter Core']
    creation = <Date 2021-01-13.11:26:55.556>
    creator = 'tholl'
    dependencies = []
    files = ['49739']
    hgrepos = []
    issue_num = 42924
    keywords = ['patch']
    message_count = 4.0
    messages = ['385017', '385046', '391977', '391978']
    nosy_count = 5.0
    nosy_names = ['lukasz.langa', 'python-dev', 'serhiy.storchaka', 'miss-islington', 'tholl']
    pr_nums = ['24208', '24211', '24212']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42924'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10']

    @TobiasHoll
    Copy link
    Mannequin Author

    TobiasHoll mannequin commented Jan 13, 2021

    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.

    @TobiasHoll TobiasHoll mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Jan 13, 2021
    @serhiy-storchaka
    Copy link
    Member

    New changeset 61d8c54 by Tobias Holl in branch 'master':
    bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208)
    61d8c54

    @ambv
    Copy link
    Contributor

    ambv commented Apr 26, 2021

    New changeset d0698c6 by Miss Islington (bot) in branch '3.9':
    bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208) (bpo-24211)
    d0698c6

    @ambv
    Copy link
    Contributor

    ambv commented Apr 26, 2021

    New changeset e1203e8 by Miss Islington (bot) in branch '3.8':
    bpo-42924: Fix incorrect copy in bytearray_repeat (GH-24208) (bpo-24212)
    e1203e8

    @ambv ambv closed this as completed Apr 26, 2021
    @ambv ambv closed this as completed Apr 26, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants