]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.8] bpo-39068: Fix race condition in base64 (GH-17627) (GH-24022)
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 1 Jan 2021 17:41:49 +0000 (19:41 +0200)
committerGitHub <noreply@github.com>
Fri, 1 Jan 2021 17:41:49 +0000 (19:41 +0200)
There was a race condition in base64 in lazy initialization of multiple globals.
(cherry picked from commit 9655434cca5dfbea97bf6d355aec028e840b289c)

Co-authored-by: Brandon Stansbury <brandonrstansbury@gmail.com>
Lib/base64.py
Misc/ACKS
Misc/NEWS.d/next/Library/2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst [new file with mode: 0644]

index 2e70223dfe78244739be541c439f64e4f6acb28f..54297668585d8465b047775f46a43eab5179f098 100755 (executable)
@@ -320,7 +320,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]
 
@@ -428,7 +428,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)
index 6ae882479d4363ebfb67d10093df15d163c8b5a4..8ca1f64c9f5f6a20429994810eda66c5ba76e469 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1607,6 +1607,7 @@ Tage Stabell-Kulo
 Quentin Stafford-Fraser
 Frank Stajano
 Joel Stanley
+Brandon Stansbury
 Anthony Starks
 David Steele
 Oliver Steele
diff --git a/Misc/NEWS.d/next/Library/2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst b/Misc/NEWS.d/next/Library/2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst
new file mode 100644 (file)
index 0000000..fe6503f
--- /dev/null
@@ -0,0 +1,2 @@
+Fix initialization race condition in :func:`a85encode` and :func:`b85encode`
+in :mod:`base64`. Patch by Brandon Stansbury.