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

Fix base64-codec and bz2-codec incremental decoders #71986

Open
vadmium opened this issue Aug 19, 2016 · 1 comment
Open

Fix base64-codec and bz2-codec incremental decoders #71986

vadmium opened this issue Aug 19, 2016 · 1 comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@vadmium
Copy link
Member

vadmium commented Aug 19, 2016

BPO 27799
Nosy @vadmium
Files
  • base64-decoder.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 = None
    closed_at = None
    created_at = <Date 2016-08-19.11:52:00.605>
    labels = ['type-bug', 'library']
    title = 'Fix base64-codec and bz2-codec incremental decoders'
    updated_at = <Date 2016-08-19.11:52:00.605>
    user = 'https://github.com/vadmium'

    bugs.python.org fields:

    activity = <Date 2016-08-19.11:52:00.605>
    actor = 'martin.panter'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2016-08-19.11:52:00.605>
    creator = 'martin.panter'
    dependencies = []
    files = ['44149']
    hgrepos = []
    issue_num = 27799
    keywords = ['patch']
    message_count = 1.0
    messages = ['273106']
    nosy_count = 1.0
    nosy_names = ['martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue27799'
    versions = ['Python 2.7', 'Python 3.5', 'Python 3.6']

    @vadmium
    Copy link
    Member Author

    vadmium commented Aug 19, 2016

    This is split off a large patch I posted at bpo-20132. My new patch here fixes the following two flaws.

    1. There is special code in the bz2 decoder that returns an empty text str object at EOF, even though bz2-codec is a bytes-to-bytes codec:
    >>> import codecs
    >>> decoder = codecs.getincrementaldecoder("bz2")()
    >>> decoder.decode(codecs.encode(b"data", "bz2"))
    b'data'
    >>> decoder.decode(b"", final=True)  # Should return bytes object
    ''
    
    2. The base64 decoder does not handle partial sets of four codes, because it treats each input chunk as a stand-alone base64 encoding:
    >>> tuple(codecs.iterdecode((b"AA", b"AA\r\n"), "base64"))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.5/codecs.py", line 1039, in iterdecode
        output = decoder.decode(input)
      File "/usr/lib/python3.5/encodings/base64_codec.py", line 35, in decode
        return base64.decodebytes(input)
      File "/usr/lib/python3.5/base64.py", line 554, in decodebytes
        return binascii.a2b_base64(s)
    binascii.Error: Incorrect padding

    @vadmium vadmium added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 19, 2016
    @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
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    Status: No status
    Development

    No branches or pull requests

    1 participant