Skip to content

Commit 9655434

Browse files
authored
bpo-39068: Fix race condition in base64 (GH-17627)
There was a race condition in base64 in lazy initialization of multiple globals.
1 parent f421bfc commit 9655434

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

Lib/base64.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False):
344344
global _a85chars, _a85chars2
345345
# Delay the initialization of tables to not waste memory
346346
# if the function is never called
347-
if _a85chars is None:
347+
if _a85chars2 is None:
348348
_a85chars = [bytes((i,)) for i in range(33, 118)]
349349
_a85chars2 = [(a + b) for a in _a85chars for b in _a85chars]
350350

@@ -452,7 +452,7 @@ def b85encode(b, pad=False):
452452
global _b85chars, _b85chars2
453453
# Delay the initialization of tables to not waste memory
454454
# if the function is never called
455-
if _b85chars is None:
455+
if _b85chars2 is None:
456456
_b85chars = [bytes((i,)) for i in _b85alphabet]
457457
_b85chars2 = [(a + b) for a in _b85chars for b in _b85chars]
458458
return _85encode(b, _b85chars, _b85chars2, pad)

Misc/ACKS

+1
Original file line numberDiff line numberDiff line change
@@ -1659,6 +1659,7 @@ Quentin Stafford-Fraser
16591659
Frank Stajano
16601660
Joel Stanley
16611661
Kyle Stanley
1662+
Brandon Stansbury
16621663
Anthony Starks
16631664
David Steele
16641665
Oliver Steele
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix initialization race condition in :func:`a85encode` and :func:`b85encode`
2+
in :mod:`base64`. Patch by Brandon Stansbury.

0 commit comments

Comments
 (0)