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

doc: clarify that struct.pack_into writes 0x00 for pad bytes #65002

Closed
bsder mannequin opened this issue Feb 28, 2014 · 5 comments
Closed

doc: clarify that struct.pack_into writes 0x00 for pad bytes #65002

bsder mannequin opened this issue Feb 28, 2014 · 5 comments
Labels
3.11 only security fixes docs Documentation in the Doc dir easy type-bug An unexpected behavior, bug, or error

Comments

@bsder
Copy link
Mannequin

bsder mannequin commented Feb 28, 2014

BPO 20803
Nosy @bitdancer, @DonnaDia
PRs
  • bpo-20803: doc: clarify that struct.pack_into writes 0x00 for pad bytes #28047
  • 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 = None
    created_at = <Date 2014-02-28.09:17:29.332>
    labels = ['easy', '3.11', 'type-bug', 'docs']
    title = 'doc: clarify that struct.pack_into writes 0x00 for pad bytes'
    updated_at = <Date 2021-10-09.09:20:20.290>
    user = 'https://bugs.python.org/bsder'

    bugs.python.org fields:

    activity = <Date 2021-10-09.09:20:20.290>
    actor = 'komugi'
    assignee = 'docs@python'
    closed = False
    closed_date = None
    closer = None
    components = ['Documentation']
    creation = <Date 2014-02-28.09:17:29.332>
    creator = 'bsder'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 20803
    keywords = ['patch', 'easy']
    message_count = 4.0
    messages = ['212416', '212433', '400554', '403526']
    nosy_count = 5.0
    nosy_names = ['bsder', 'r.david.murray', 'docs@python', 'DonnaDia', 'komugi']
    pr_nums = ['28047']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue20803'
    versions = ['Python 3.11']

    @bsder
    Copy link
    Mannequin Author

    bsder mannequin commented Feb 28, 2014

    This code did something unexpected to me:
    >>> a = bytearray('1234')
    >>> a
    bytearray(b'1234')
    >>> struct.pack_into('xBxB', a, 0, 0x59, 0x5A)
    >>> a
    bytearray(b'\x00Y\x00Z')

    The unexpected part was that the 'x' pad byte formatter actually *overwrote* the bytes to 0 rather than leaving them alone.

    Not necessarily a bug, but the fact that the pad byte writes 0x00 rather than being untouched/ignored should be documented.

    @bsder bsder mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Feb 28, 2014
    @bitdancer
    Copy link
    Member

    Contrawise, I would have found it very surprising if it had not padded with null bytes, but yes, the docs could be explicit about it by saying that 'x' padding means inserting null bytes.

    @iritkatriel iritkatriel added easy 3.11 only security fixes docs Documentation in the Doc dir and removed interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Jun 18, 2021
    @iritkatriel iritkatriel changed the title struct.pack_into writes 0x00 for pad bytes doc: clarify that struct.pack_into writes 0x00 for pad bytes Jun 18, 2021
    @DonnaDia
    Copy link
    Mannequin

    DonnaDia mannequin commented Aug 29, 2021

    I'm working on this

    @komugi
    Copy link
    Mannequin

    komugi mannequin commented Oct 9, 2021

    The PR is stale. Can I work on it ?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 28, 2022
    miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 28, 2022
    miss-islington added a commit that referenced this issue Nov 3, 2022
    miss-islington added a commit that referenced this issue Nov 3, 2022
    @hauntsaninja
    Copy link
    Contributor

    Thanks, looks like this has been completed

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes docs Documentation in the Doc dir easy type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants