Repository navigation
binascii.a2b_base64 ignores padding inside a string #94703
Copy link
Copy link
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jul 9, 2022 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 allowedThe 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
Does it reject this input?
import binascii binascii.a2b_base64(b'aaaa=aa==', strict_mode=True)?
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 allowedIs it because python 3.10.5 uses REF 4648. https://docs.python.org/3/library/base64.html
Hi @DemiMarie,
This behavior is normal in 3.10, since thestrict_modeflag 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 allowedFor further information, please read:
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
The following code should raise
binascii.Errorbut does not:It appears (from looking at the source code) that this is also the case in 3.11, even in strict mode.
Your environment