Skip to content

Commit 5a400ce

Browse files
authored
gh-152851: fix a crash when copying a BLAKE-2s/2b object (#153008)
1 parent 8b1dbb1 commit 5a400ce

2 files changed

Lines changed: 6 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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,10 @@ blake2_blake2b_copy_unlocked(Blake2Object *self, Blake2Object *cpy)
757757
} \
758758
} while (0)
759759

760+
// Ensure that the implementation type is consistent with the HACL* state.
761+
// See https://github.com/python/cpython/issues/152851 for details.
762+
cpy->impl = self->impl;
763+
760764
switch (self->impl) {
761765
#if _Py_HACL_CAN_COMPILE_VEC256
762766
case Blake2b_256:
@@ -778,7 +782,6 @@ blake2_blake2b_copy_unlocked(Blake2Object *self, Blake2Object *cpy)
778782
Py_UNREACHABLE();
779783
}
780784
#undef BLAKE2_COPY
781-
cpy->impl = self->impl;
782785
return 0;
783786

784787
error:

0 commit comments

Comments
 (0)