]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-152851: fix a crash when copying a BLAKE-2s/2b object (#153008)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sat, 4 Jul 2026 10:09:42 +0000 (12:09 +0200)
committerGitHub <noreply@github.com>
Sat, 4 Jul 2026 10:09:42 +0000 (12:09 +0200)
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 b71dd20925611efb9eed66743e3fc4484ca60ea6..ac7265bb9d6836c970a6d7844f2d83c4b98c8c1c 100644 (file)
@@ -757,6 +757,10 @@ blake2_blake2b_copy_unlocked(Blake2Object *self, Blake2Object *cpy)
         }                                                                   \
     } while (0)
 
+    // 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:
@@ -778,7 +782,6 @@ blake2_blake2b_copy_unlocked(Blake2Object *self, Blake2Object *cpy)
             Py_UNREACHABLE();
     }
 #undef BLAKE2_COPY
-    cpy->impl = self->impl;
     return 0;
 
 error: