]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-141141: Make base64.b85decode() thread safe (GH-141149) (GH-141184)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 7 Nov 2025 11:14:51 +0000 (12:14 +0100)
committerGitHub <noreply@github.com>
Fri, 7 Nov 2025 11:14:51 +0000 (11:14 +0000)
(cherry picked from commit a7bf27f7f521384a8964718bdb58a5cb113bb3ec)

Co-authored-by: Benel Tayar <86257734+beneltayar@users.noreply.github.com>
Lib/base64.py
Misc/NEWS.d/next/Library/2025-11-06-15-11-50.gh-issue-141141.tgIfgH.rst [new file with mode: 0644]

index 5d78cc09f40cd3e9da6a110dd4ad8347e2141856..cfc57626c40ba915dac440727e19ca1717c3ae2d 100644 (file)
@@ -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
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 (file)
index 0000000..f59ccfb
--- /dev/null
@@ -0,0 +1 @@
+Fix a thread safety issue with :func:`base64.b85decode`. Contributed by Benel Tayar.