-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
The b85decode implementation starts like this:
def b85decode(b):
"""Decode the base85-encoded bytes-like object or ASCII string b
The result is returned as a bytes object.
"""
global _b85dec
# Delay the initialization of tables to not waste memory
# if the function is never called
if _b85dec is None:
_b85dec = [None] * 256
for i, c in enumerate(_b85alphabet):
_b85dec[c] = i
... # decode logicThis can result in a thread safety issue if a thread switch happens after _b85dec = [None] * 256 but before _b85dec was fully populated
If that happens, and a different thread calls b85decode, it will proceed to the decode logic with an invalid value in the _b85dec global variable.
I was able to reproduce this issue locally on my machine with some mock trickery to make the thread sleep at the right time
CPython versions tested on:
CPython main branch, 3.11
Operating systems tested on:
Windows
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-free-threadingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error