From 0d6e40744ae40ff397883ff90ca235efd3b63f18 Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Fri, 1 Jan 2021 12:42:44 -0800 Subject: [PATCH] bpo-39068: Fix race condition in base64 (GH-17627) There was a race condition in base64 in lazy initialization of multiple globals. (cherry picked from commit 9655434cca5dfbea97bf6d355aec028e840b289c) Co-authored-by: Brandon Stansbury --- Lib/base64.py | 4 ++-- Misc/ACKS | 1 + .../next/Library/2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst | 2 ++ 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst diff --git a/Lib/base64.py b/Lib/base64.py index a28109f8a7f..ec3823b724a 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -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) diff --git a/Misc/ACKS b/Misc/ACKS index a20c41f1cb1..58a4accd134 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1641,6 +1641,7 @@ Quentin Stafford-Fraser Frank Stajano Joel Stanley Kyle 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 index 00000000000..fe6503fdce6 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst @@ -0,0 +1,2 @@ +Fix initialization race condition in :func:`a85encode` and :func:`b85encode` +in :mod:`base64`. Patch by Brandon Stansbury.