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

binascii.a2b_base64 strict mode accepts invalid base64 input #118314

Closed
zhangyoufu opened this issue Apr 26, 2024 · 0 comments
Closed

binascii.a2b_base64 strict mode accepts invalid base64 input #118314

zhangyoufu opened this issue Apr 26, 2024 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@zhangyoufu
Copy link
Contributor

zhangyoufu commented Apr 26, 2024

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

@zhangyoufu zhangyoufu added the type-bug An unexpected behavior, bug, or error label Apr 26, 2024
zhangyoufu added a commit to zhangyoufu/cpython that referenced this issue Apr 26, 2024
zhangyoufu added a commit to zhangyoufu/cpython that referenced this issue Apr 26, 2024
zhangyoufu added a commit to zhangyoufu/cpython that referenced this issue Apr 26, 2024
@zhangyoufu zhangyoufu changed the title binascii.a2b_base64 with strict_mode=True accepts invalid base64 input binascii.a2b_base64 strict mode accepts invalid base64 input Apr 26, 2024
terryjreedy added a commit to zhangyoufu/cpython that referenced this issue Apr 26, 2024
encukou pushed a commit that referenced this issue May 7, 2024
…H-118320)

Fix an edge case in `binascii.a2b_base64` strict mode, where
excessive padding was not detected when no padding is necessary.

Co-authored-by: Terry Jan Reedy <[email protected]>
Co-authored-by: Pieter Eendebak <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 7, 2024
…mode (pythonGH-118320)

Fix an edge case in `binascii.a2b_base64` strict mode, where
excessive padding was not detected when no padding is necessary.

(cherry picked from commit fe47d9b)

Co-authored-by: Youfu Zhang <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
Co-authored-by: Pieter Eendebak <[email protected]>
encukou pushed a commit that referenced this issue May 7, 2024
… mode (GH-118320) (GH-118691)

gh-118314: Fix padding edge case in binascii.a2b_base64 strict mode (GH-118320)

Fix an edge case in `binascii.a2b_base64` strict mode, where
excessive padding was not detected when no padding is necessary.

(cherry picked from commit fe47d9b)

Co-authored-by: Youfu Zhang <[email protected]>
Co-authored-by: Terry Jan Reedy <[email protected]>
Co-authored-by: Pieter Eendebak <[email protected]>
@encukou encukou closed this as completed May 7, 2024
SonicField pushed a commit to SonicField/cpython that referenced this issue May 8, 2024
…mode (pythonGH-118320)

Fix an edge case in `binascii.a2b_base64` strict mode, where
excessive padding was not detected when no padding is necessary.

Co-authored-by: Terry Jan Reedy <[email protected]>
Co-authored-by: Pieter Eendebak <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants