]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-152851: fix a crash when copying a BLAKE-2s/2b object (GH-153008) (#153012)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sat, 4 Jul 2026 10:46:47 +0000 (12:46 +0200)
committerGitHub <noreply@github.com>
Sat, 4 Jul 2026 10:46:47 +0000 (10:46 +0000)
[3.14] gh-152851: fix a crash when copying a BLAKE-2s/2b object (GH-153008)
(cherry picked from commit 5a400ceafbbd4456ac65fbdbcf5d62ce9e8e4f9f)

Misc/NEWS.d/next/Library/2026-07-04-11-14-06.gh-issue-152851.diYvTf.rst [new file with mode: 0644]
Modules/blake2module.c

diff --git a/Misc/NEWS.d/next/Library/2026-07-04-11-14-06.gh-issue-152851.diYvTf.rst b/Misc/NEWS.d/next/Library/2026-07-04-11-14-06.gh-issue-152851.diYvTf.rst
new file mode 100644 (file)
index 0000000..aab033e
--- /dev/null
@@ -0,0 +1,2 @@
+Prevent a crash when allocation fails while copying a :func:`BLAKE-2s/2b
+<hashlib.blake2b>` object. Patch by Bénédikt Tran.
index e31fa8131f1ecf4d2d1ebe7d2085c36a8e847189..c4fbd204d566d70a93c0269b30c44c78119b2590 100644 (file)
@@ -732,6 +732,11 @@ static int
 blake2_blake2b_copy_locked(Blake2Object *self, Blake2Object *cpy)
 {
     assert(cpy != NULL);
+
+    // Ensure that the implementation type is consistent with the HACL* state.
+    // See https://github.com/python/cpython/issues/152851 for details.
+    cpy->impl = self->impl;
+
     switch (self->impl) {
 #if _Py_HACL_CAN_COMPILE_VEC256
         case Blake2b_256: {
@@ -768,7 +773,6 @@ blake2_blake2b_copy_locked(Blake2Object *self, Blake2Object *cpy)
         default:
             Py_UNREACHABLE();
     }
-    cpy->impl = self->impl;
     return 0;
 
 error: