-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed as not planned
Closed as not planned
Copy link
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
Description
Bug report
Bug description:
base64.b64encode and base64.b64decode use asymmetric translation logic when the altchars argument contains duplicate bytes. This causes data to become corrupted during a roundtrip (encode -> decode).
import base64
data_in = b'\x00\x00\x00\x03\xe0'
altchars = b'\x00\x00'
encoded = base64.b64encode(data_in, altchars=altchars)
data_out = base64.b64decode(encoded, altchars=altchars)
assert data_in == data_out, "Roundtrip failed! Data was corrupted."Traceback (most recent call last):
File "/data/src/test.py", line 8, in <module>
assert data_in == data_out, "Roundtrip failed! Data was corrupted."
^^^^^^^^^^^^^^^^^^^
AssertionError: Roundtrip failed! Data was corrupted.The script should execute successfully and the assertion should pass.
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory