https://github.com/python/cpython/commit/878b5e256aa40c45e12a0cd5c63f8a249f7c3704
commit: 878b5e256aa40c45e12a0cd5c63f8a249f7c3704
branch: main
author: Bénédikt Tran <[email protected]>
committer: picnixz <[email protected]>
date: 2026-09-06T18:49:09+02:00
summary:

gh-155835: fix `digest_size` data race on BLAKE-2 objects (#155839)

files:
A Misc/NEWS.d/next/Library/2026-08-15-13-18-01.gh-issue-155835.mlyLWp.rst
M Lib/test/test_hashlib.py
M Modules/blake2module.c

diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py
index b511c160c9260f..a718be415b9905 100644
--- a/Lib/test/test_hashlib.py
+++ b/Lib/test/test_hashlib.py
@@ -1505,6 +1505,12 @@ def test_HACL_sha3_attributes(self, size, attrname):
     def test_HACL_shake_attributes(self, size, attrname):
         self.check_HACL_attribute(_sha3, f"shake_{size}", attrname)
 
+    @requires_blake2
+    @support.subTests("version", ["blake2s", "blake2b"])
+    @support.subTests("attrname", ["block_size", "digest_size"])
+    def test_HACL_blake2_attributes(self, version, attrname):
+        self.check_HACL_attribute(_blake2, version, attrname)
+
 
 if __name__ == "__main__":
     unittest.main()
diff --git 
a/Misc/NEWS.d/next/Library/2026-08-15-13-18-01.gh-issue-155835.mlyLWp.rst 
b/Misc/NEWS.d/next/Library/2026-08-15-13-18-01.gh-issue-155835.mlyLWp.rst
new file mode 100644
index 00000000000000..9ef7d0694e66c3
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-08-15-13-18-01.gh-issue-155835.mlyLWp.rst
@@ -0,0 +1,2 @@
+:mod:`hashlib`: Fix a data race when accessing 
:attr:`~hashlib.hash.digest_size`
+on BLAKE-2 objects. Patch by Bénédikt Tran.
diff --git a/Modules/blake2module.c b/Modules/blake2module.c
index ac7265bb9d6836..c69c4259b12666 100644
--- a/Modules/blake2module.c
+++ b/Modules/blake2module.c
@@ -950,7 +950,9 @@ static PyObject *
 py_blake2b_get_digest_size(PyObject *op, void *Py_UNUSED(closure))
 {
     Blake2Object *self = _Blake2Object_CAST(op);
+    HASHLIB_ACQUIRE_LOCK(self);
     Hacl_Hash_Blake2b_index info = hacl_get_blake2_info(self);
+    HASHLIB_RELEASE_LOCK(self);
     return PyLong_FromLong(info.digest_length);
 }
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to