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.__mod__() truncates on first \x00 #73259

Closed
sanjioh mannequin opened this issue Dec 26, 2016 · 4 comments
Closed

bytearray.__mod__() truncates on first \x00 #73259

sanjioh mannequin opened this issue Dec 26, 2016 · 4 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@sanjioh
Copy link
Mannequin

sanjioh mannequin commented Dec 26, 2016

BPO 29073
Nosy @vstinner, @freakboy3742, @ethanfurman, @serhiy-storchaka, @sanjioh
Files
  • bytearray_format_nul.patch
  • 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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2016-12-28.07:59:58.083>
    created_at = <Date 2016-12-26.09:52:44.464>
    labels = ['interpreter-core', 'type-bug']
    title = 'bytearray.__mod__() truncates on first \\x00'
    updated_at = <Date 2016-12-28.07:59:58.082>
    user = 'https://github.com/sanjioh'

    bugs.python.org fields:

    activity = <Date 2016-12-28.07:59:58.082>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2016-12-28.07:59:58.083>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2016-12-26.09:52:44.464>
    creator = 'sanjioh'
    dependencies = []
    files = ['46039']
    hgrepos = []
    issue_num = 29073
    keywords = ['patch']
    message_count = 4.0
    messages = ['284018', '284020', '284021', '284160']
    nosy_count = 6.0
    nosy_names = ['vstinner', 'freakboy3742', 'ethan.furman', 'python-dev', 'serhiy.storchaka', 'sanjioh']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue29073'
    versions = ['Python 3.5']

    @sanjioh
    Copy link
    Mannequin Author

    sanjioh mannequin commented Dec 26, 2016

    Originally posted by Russell Keith-Magee on Twitter:
    https://twitter.com/freakboy3742/status/812609675283681280

    Reproduced successfully on Python 3.5.2

    >>> x = bytearray(1)
    >>> y = {}
    >>> x % y
    Python3.5: bytearray(b'')
    Python3.6: bytearray(b'\x00')
    
    also:
    >>> bytearray([0,1]) % {} # same with [], (), range(42)
    bytearray(b'')
    >>> bytearray([1,0]) % {}
    bytearray(b'\x01')

    @sanjioh sanjioh mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Dec 26, 2016
    @freakboy3742
    Copy link
    Mannequin

    freakboy3742 mannequin commented Dec 26, 2016

    Since I was named dropped; it's worth pointing out that this has evidently been fixed - intentionally or otherwise - in 3.6.

    It wasn't an issue in 3.4 and earlier because __mod__ wasn't implemented for bytestrings.

    @serhiy-storchaka
    Copy link
    Member

    Indeed, there is an inconsistency between bytes and bytearray in 3.5:

    >>> b'a\0b' % ()
    b'a\x00b'
    >>> bytearray(b'a\0b') % ()
    bytearray(b'a')

    It was unintentionally fixed in bpo-25399.

    Proposed patch fixes the issue.

    @serhiy-storchaka serhiy-storchaka self-assigned this Dec 28, 2016
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 28, 2016

    New changeset 277b36596a54 by Serhiy Storchaka in branch '3.5':
    Issue bpo-29073: bytearray formatting no longer truncates on first null byte.
    https://hg.python.org/cpython/rev/277b36596a54

    New changeset 9b77e3a586b0 by Serhiy Storchaka in branch '3.6':
    Issue bpo-29073: Added a test for bytearray formatting with null byte.
    https://hg.python.org/cpython/rev/9b77e3a586b0

    New changeset 82bfdf599e24 by Serhiy Storchaka in branch 'default':
    Issue bpo-29073: Added a test for bytearray formatting with null byte.
    https://hg.python.org/cpython/rev/82bfdf599e24

    @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
    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

    1 participant