Skip to content

Commit 353bfc8

Browse files
[3.13] gh-141141: Make base64.b85decode() thread safe (GH-141149) (GH-141185)
(cherry picked from commit a7bf27f) Co-authored-by: Benel Tayar <[email protected]>
1 parent dcd2dba commit 353bfc8

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Lib/base64.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,9 +465,12 @@ def b85decode(b):
465465
# Delay the initialization of tables to not waste memory
466466
# if the function is never called
467467
if _b85dec is None:
468-
_b85dec = [None] * 256
468+
# we don't assign to _b85dec directly to avoid issues when
469+
# multiple threads call this function simultaneously
470+
b85dec_tmp = [None] * 256
469471
for i, c in enumerate(_b85alphabet):
470-
_b85dec[c] = i
472+
b85dec_tmp[c] = i
473+
_b85dec = b85dec_tmp
471474

472475
b = _bytes_from_decode_data(b)
473476
padding = (-len(b)) % 5
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a thread safety issue with :func:`base64.b85decode`. Contributed by Benel Tayar.

0 commit comments

Comments
 (0)