Skip to content

Commit 1c413e0

Browse files
Make base64.b85decode thread safe - issue 141141
1 parent 1697cb5 commit 1c413e0

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-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

0 commit comments

Comments
 (0)