Skip to content

binascii.a2b_base64 strict mode accepts invalid base64 input #118314

Closed

Description

@zhangyoufu

Bug report

Bug description:

>>> import binascii
>>> f = lambda s: binascii.a2b_base64(s, strict_mode=True)
>>> f('AAAA')
b'\x00\x00\x00'
>>> f('AAAA=')
b'\x00\x00\x00'
>>> f('AAAA==')
b'\x00\x00\x00'
>>> f('AAAA===')
b'\x00\x00\x00'
>>> f('AAAA====')
b'\x00\x00\x00'
>>> f('AAAA=====')
b'\x00\x00\x00'

Doc/library/binascii.rst defines that a valid base64 "Contains no excess data after padding (including excess padding, newlines, etc.)". However, current implement does not handle the edge case of excess padding after no padding.

CPython versions tested on:

3.12

Operating systems tested on:

macOS

Linked PRs

Activity

  1. changed the title [-]binascii.a2b_base64 with strict_mode=True accepts invalid base64 input[/-] [+]binascii.a2b_base64 strict mode accepts invalid base64 input[/+] on Apr 26, 2024
  2. added a commit that references this issue on May 7, 2024
  3. added a commit that references this issue on May 7, 2024
  4. added a commit that references this issue on May 7, 2024
  5. added a commit that references this issue on May 8, 2024
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 error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions