Skip to content

Commit a7bf27f

Browse files
authored
gh-141141: Make base64.b85decode() thread safe (GH-141149)
1 parent 9a19900 commit a7bf27f

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
@@ -462,9 +462,12 @@ def b85decode(b):
462462
# Delay the initialization of tables to not waste memory
463463
# if the function is never called
464464
if _b85dec is None:
465-
_b85dec = [None] * 256
465+
# we don't assign to _b85dec directly to avoid issues when
466+
# multiple threads call this function simultaneously
467+
b85dec_tmp = [None] * 256
466468
for i, c in enumerate(_b85alphabet):
467-
_b85dec[c] = i
469+
b85dec_tmp[c] = i
470+
_b85dec = b85dec_tmp
468471

469472
b = _bytes_from_decode_data(b)
470473
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)