Skip to content

Commit d786fbd

Browse files
authored
[3.14] gh-152851: fix a crash when copying a BLAKE-2s/2b object (GH-153008) (#153012)
[3.14] gh-152851: fix a crash when copying a BLAKE-2s/2b object (GH-153008) (cherry picked from commit 5a400ce)
1 parent 4413f32 commit d786fbd

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Prevent a crash when allocation fails while copying a :func:`BLAKE-2s/2b
2+
<hashlib.blake2b>` object. Patch by Bénédikt Tran.

Modules/blake2module.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,11 @@ static int
732732
blake2_blake2b_copy_locked(Blake2Object *self, Blake2Object *cpy)
733733
{
734734
assert(cpy != NULL);
735+
736+
// Ensure that the implementation type is consistent with the HACL* state.
737+
// See https://github.com/python/cpython/issues/152851 for details.
738+
cpy->impl = self->impl;
739+
735740
switch (self->impl) {
736741
#if _Py_HACL_CAN_COMPILE_VEC256
737742
case Blake2b_256: {
@@ -768,7 +773,6 @@ blake2_blake2b_copy_locked(Blake2Object *self, Blake2Object *cpy)
768773
default:
769774
Py_UNREACHABLE();
770775
}
771-
cpy->impl = self->impl;
772776
return 0;
773777

774778
error:

0 commit comments

Comments
 (0)