From 1c413e0e394dbf6bd4e036350525b81ab195542b Mon Sep 17 00:00:00 2001 From: Benel Tayar Date: Thu, 6 Nov 2025 16:01:18 +0200 Subject: [PATCH 1/3] Make base64.b85decode thread safe - issue 141141 --- Lib/base64.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Lib/base64.py b/Lib/base64.py index 5d78cc09f40cd3..abe70a32bf73d6 100644 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -462,9 +462,12 @@ def b85decode(b): # Delay the initialization of tables to not waste memory # if the function is never called if _b85dec is None: - _b85dec = [None] * 256 + # we don't assign to _b85dec directly to avoid issues when + # multiple threads call this function simultaneously + _b85dec_tmp = [None] * 256 for i, c in enumerate(_b85alphabet): - _b85dec[c] = i + _b85dec_tmp[c] = i + _b85dec = _b85dec_tmp b = _bytes_from_decode_data(b) padding = (-len(b)) % 5 From 4796813fe522399a1173e84c0b65fb6c4b407e66 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 6 Nov 2025 15:11:51 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-11-06-15-11-50.gh-issue-141141.tgIfgH.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-11-06-15-11-50.gh-issue-141141.tgIfgH.rst diff --git a/Misc/NEWS.d/next/Library/2025-11-06-15-11-50.gh-issue-141141.tgIfgH.rst b/Misc/NEWS.d/next/Library/2025-11-06-15-11-50.gh-issue-141141.tgIfgH.rst new file mode 100644 index 00000000000000..f59ccfb33e7669 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-11-06-15-11-50.gh-issue-141141.tgIfgH.rst @@ -0,0 +1 @@ +Fix a thread safety issue with :func:`base64.b85decode`. Contributed by Benel Tayar. From c4d8f4e9d6c68decbd215e956a5bd1c27b229096 Mon Sep 17 00:00:00 2001 From: Benel Tayar Date: Fri, 7 Nov 2025 12:19:10 +0200 Subject: [PATCH 3/3] rename b85dec_tmp --- Lib/base64.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/base64.py b/Lib/base64.py index abe70a32bf73d6..cfc57626c40ba9 100644 --- a/Lib/base64.py +++ b/Lib/base64.py @@ -464,10 +464,10 @@ def b85decode(b): if _b85dec is None: # we don't assign to _b85dec directly to avoid issues when # multiple threads call this function simultaneously - _b85dec_tmp = [None] * 256 + b85dec_tmp = [None] * 256 for i, c in enumerate(_b85alphabet): - _b85dec_tmp[c] = i - _b85dec = _b85dec_tmp + b85dec_tmp[c] = i + _b85dec = b85dec_tmp b = _bytes_from_decode_data(b) padding = (-len(b)) % 5