Skip to content

Commit 878b5e2

Browse files
authored
gh-155835: fix digest_size data race on BLAKE-2 objects (#155839)
1 parent 90ac539 commit 878b5e2

3 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_hashlib.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,12 @@ def test_HACL_sha3_attributes(self, size, attrname):
15051505
def test_HACL_shake_attributes(self, size, attrname):
15061506
self.check_HACL_attribute(_sha3, f"shake_{size}", attrname)
15071507

1508+
@requires_blake2
1509+
@support.subTests("version", ["blake2s", "blake2b"])
1510+
@support.subTests("attrname", ["block_size", "digest_size"])
1511+
def test_HACL_blake2_attributes(self, version, attrname):
1512+
self.check_HACL_attribute(_blake2, version, attrname)
1513+
15081514

15091515
if __name__ == "__main__":
15101516
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`hashlib`: Fix a data race when accessing :attr:`~hashlib.hash.digest_size`
2+
on BLAKE-2 objects. Patch by Bénédikt Tran.

Modules/blake2module.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,9 @@ static PyObject *
950950
py_blake2b_get_digest_size(PyObject *op, void *Py_UNUSED(closure))
951951
{
952952
Blake2Object *self = _Blake2Object_CAST(op);
953+
HASHLIB_ACQUIRE_LOCK(self);
953954
Hacl_Hash_Blake2b_index info = hacl_get_blake2_info(self);
955+
HASHLIB_RELEASE_LOCK(self);
954956
return PyLong_FromLong(info.digest_length);
955957
}
956958

0 commit comments

Comments
 (0)