Skip to content

Commit 614cd80

Browse files
drmonkeyseeserhiy-storchaka
authored andcommitted
[3.8] bpo-39068: Fix race condition in base64 (pythonGH-17627)
There was a race condition in base64 in lazy initialization of multiple globals.. (cherry picked from commit 9655434) Co-authored-by: Brandon Stansbury <brandonrstansbury@gmail.com>
1 parent 741f22d commit 614cd80

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lib/base64.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False):
320320
global _a85chars, _a85chars2
321321
# Delay the initialization of tables to not waste memory
322322
# if the function is never called
323-
if _a85chars is None:
323+
if _a85chars2 is None:
324324
_a85chars = [bytes((i,)) for i in range(33, 118)]
325325
_a85chars2 = [(a + b) for a in _a85chars for b in _a85chars]
326326

@@ -428,7 +428,7 @@ def b85encode(b, pad=False):
428428
global _b85chars, _b85chars2
429429
# Delay the initialization of tables to not waste memory
430430
# if the function is never called
431-
if _b85chars is None:
431+
if _b85chars2 is None:
432432
_b85chars = [bytes((i,)) for i in _b85alphabet]
433433
_b85chars2 = [(a + b) for a in _b85chars for b in _b85chars]
434434
return _85encode(b, _b85chars, _b85chars2, pad)

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,6 +1607,7 @@ Tage Stabell-Kulo
16071607
Quentin Stafford-Fraser
16081608
Frank Stajano
16091609
Joel Stanley
1610+
Brandon Stansbury
16101611
Anthony Starks
16111612
David Steele
16121613
Oliver Steele
Lines changed: 2 additions & 0 deletions
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)