GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `binascii.a2b_base64` ignores padding inside a string · Issue #94703 · python/cpython

binascii.a2b_base64 ignores padding inside a string #94703

New issue
Copy link
New issue
Copy link
Closed
Closed
binascii.a2b_base64 ignores padding inside a string#94703
Copy link
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@DemiMarie
DemiMarie
opened on Jul 9, 2022
Issue body actions

Bug report

The following code should raise binascii.Error but does not:

import binascii
binascii.a2b_base64(b'=aa==')

It appears (from looking at the source code) that this is also the case in 3.11, even in strict mode.

Your environment

  • CPython versions tested on: 3.10
  • Operating system and architecture: Fedora 36, Linux 5.15.52, x86_64

Activity

  1. DemiMarie
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jul 9, 2022
  2. yourlefthandman commented on Jul 9, 2022

    @yourlefthandman
    yourlefthandman
    on Jul 9, 2022
    Contributor
    More actions

    When running the code from main, the behaviour is as you expect it to be :)

    >>> binascii.a2b_base64(b'=aa==', strict_mode=True)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    binascii.Error: Leading padding not allowed
    

    The following code handles it-

    if (strict_mode && ascii_len > 0 && ascii_data[0] == '=') {
        state = get_binascii_state(module);
        if (state) {
            PyErr_SetString(state->Error, "Leading padding not allowed");
        }
        goto error_end;
    }
    

    Looking at 3.11, i see the code is there too - link

  3. DemiMarie commented on Jul 10, 2022

    @DemiMarie
    DemiMarie
    on Jul 10, 2022
    Author
    More actions

    Does it reject this input?

    import binascii
    binascii.a2b_base64(b'aaaa=aa==', strict_mode=True)
    

    ?

  4. yourlefthandman commented on Jul 10, 2022

    @yourlefthandman
    yourlefthandman
    on Jul 10, 2022
    Contributor
    More actions

    Yup :)

    >>> import binascii
    >>> binascii.a2b_base64(b'aaaa=aa==', strict_mode=True)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    binascii.Error: Discontinuous padding not allowed
    
  5. Mohitduklan commented on Jul 24, 2022

    @Mohitduklan
    Mohitduklan
    on Jul 24, 2022
    More actions

    Is it because python 3.10.5 uses REF 4648. https://docs.python.org/3/library/base64.html

  6. idan22moral commented on Nov 4, 2022

    @idan22moral
    idan22moral
    on Nov 4, 2022
    Contributor
    More actions

    Hi @DemiMarie,
    This behavior is normal in 3.10, since the strict_mode flag was not introduced yet.
    In 3.11.0 it behaves as expected:

    Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import binascii
    >>> binascii.a2b_base64(b'=aa==')
    b'i'
    >>> binascii.a2b_base64(b'=aa==', strict_mode=True)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    binascii.Error: Leading padding not allowed
    >>> binascii.a2b_base64(b'aaaa=aa==')
    b'i\xa6\x9ai'
    >>> binascii.a2b_base64(b'aaaa=aa==', strict_mode=True)
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    binascii.Error: Discontinuous padding not allowed
    

    For further information, please read:

    • https://docs.python.org/3/library/binascii.html?highlight=strict_mode#binascii.a2b_base64
    • bpo-43086: Added handling for excess data in binascii.a2b_base64 #24402
  7. DemiMarie
    closed this as completedon Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.