Skip to content

Commit

Permalink
bpo-39068: Fix race condition in base64 (pythonGH-17627)
Browse files Browse the repository at this point in the history
There was a race condition in base64 in lazy initialization of multiple globals.
  • Loading branch information
drmonkeysee authored Dec 31, 2020
1 parent f421bfc commit 9655434
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Lib/base64.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False):
global _a85chars, _a85chars2
# Delay the initialization of tables to not waste memory
# if the function is never called
if _a85chars is None:
if _a85chars2 is None:
_a85chars = [bytes((i,)) for i in range(33, 118)]
_a85chars2 = [(a + b) for a in _a85chars for b in _a85chars]

Expand Down Expand Up @@ -452,7 +452,7 @@ def b85encode(b, pad=False):
global _b85chars, _b85chars2
# Delay the initialization of tables to not waste memory
# if the function is never called
if _b85chars is None:
if _b85chars2 is None:
_b85chars = [bytes((i,)) for i in _b85alphabet]
_b85chars2 = [(a + b) for a in _b85chars for b in _b85chars]
return _85encode(b, _b85chars, _b85chars2, pad)
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,7 @@ Quentin Stafford-Fraser
Frank Stajano
Joel Stanley
Kyle Stanley
Brandon Stansbury
Anthony Starks
David Steele
Oliver Steele
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix initialization race condition in :func:`a85encode` and :func:`b85encode`
in :mod:`base64`. Patch by Brandon Stansbury.

0 comments on commit 9655434

Please sign in to comment.