Skip to content

base64.b64decode error raised on valid input #145968

Description

@mayeut

Bug report

Bug description:

An error is raised for the following valid test cases using the newly introduced ignorechars parameter

import base64

assert base64.b64decode(b'/----', altchars=b'-+', ignorechars=b'/') == b'\xfb\xef\xbe'
assert base64.b64decode(b'+----', altchars=b'/-', ignorechars=b'+') == b'\xff\xff\xff'

For both we get:

binascii.Error: Invalid base64-encoded string: number of data characters (5) cannot be 1 more than a multiple of 4

In both cases, the leading byte should be ignored thus giving a 4 bytes valid input.

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Mar 15, 2026
  2. terryjreedy commented on Mar 15, 2026

    @terryjreedy
    Member

    @serhiy-storchaka I believe you introduced base64 ignorechars.

  3. changed the title [-]base64.decode error raised on valid input[/-] [+]base64.b64decode error raised on valid input[/+] on Mar 15, 2026
  4. mayeut commented on Mar 15, 2026

    @mayeut
    ContributorAuthor

    I do have a PR almost ready, I'll cc @serhiy-storchaka

  5. added a commit that references this issue on Mar 15, 2026
  6. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Mar 15, 2026
  7. added a commit that references this issue on Mar 15, 2026
  8. serhiy-storchaka commented on Mar 15, 2026

    @serhiy-storchaka
    Member

    Thank you for your report and PR, @mayeut.

  9. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions