From 04967d1d05f2a695ff7caded296791ae3f9a8f4c Mon Sep 17 00:00:00 2001 From: Brandon Stansbury Date: Mon, 16 Dec 2019 09:45:09 -0800 Subject: [PATCH 1/4] guard _b85chars2 table --- Lib/base64.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Lib/base64.py b/Lib/base64.py index 2be9c395a96674..9ecc7b24e7f5bd 100755 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -430,6 +430,7 @@ def b85encode(b, pad=False): # if the function is never called if _b85chars is None: _b85chars = [bytes((i,)) for i in _b85alphabet] + if _b85chars2 is None: _b85chars2 = [(a + b) for a in _b85chars for b in _b85chars] return _85encode(b, _b85chars, _b85chars2, pad) From bf5a325492edc09cd9386930cd24e2ae60c9687d Mon Sep 17 00:00:00 2001 From: Brandon Stansbury Date: Mon, 16 Dec 2019 11:05:43 -0800 Subject: [PATCH 2/4] only check latter var and fix a85 as well --- Lib/base64.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Lib/base64.py b/Lib/base64.py index 9ecc7b24e7f5bd..258042e625bf1a 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,9 +428,8 @@ 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: - _b85chars = [bytes((i,)) for i in _b85alphabet] 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) From 9e86e225dc43cc6ef26b71f05ced157e657fb764 Mon Sep 17 00:00:00 2001 From: Brandon Stansbury Date: Mon, 6 Jan 2020 10:07:21 -0800 Subject: [PATCH 3/4] add news and ack entries --- Misc/ACKS | 1 + .../next/Library/2020-01-06-09-57-22.bpo-39068.Ti3f9P.rst | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2020-01-06-09-57-22.bpo-39068.Ti3f9P.rst diff --git a/Misc/ACKS b/Misc/ACKS index 5f42760cb9267a..d6990848661ca2 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1595,6 +1595,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/2020-01-06-09-57-22.bpo-39068.Ti3f9P.rst b/Misc/NEWS.d/next/Library/2020-01-06-09-57-22.bpo-39068.Ti3f9P.rst new file mode 100644 index 00000000000000..fe6503fdce6b63 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-01-06-09-57-22.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. From 6562ee43e5f6109a656741c90ac5c6333c0a4640 Mon Sep 17 00:00:00 2001 From: Brandon Stansbury Date: Mon, 6 Jan 2020 10:55:17 -0800 Subject: [PATCH 4/4] rename file to match time the bug was filed --- ...-39068.Ti3f9P.rst => 2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Misc/NEWS.d/next/Library/{2020-01-06-09-57-22.bpo-39068.Ti3f9P.rst => 2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst} (100%) diff --git a/Misc/NEWS.d/next/Library/2020-01-06-09-57-22.bpo-39068.Ti3f9P.rst b/Misc/NEWS.d/next/Library/2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst similarity index 100% rename from Misc/NEWS.d/next/Library/2020-01-06-09-57-22.bpo-39068.Ti3f9P.rst rename to Misc/NEWS.d/next/Library/2019-12-16-17-55-31.bpo-39068.Ti3f9P.rst