Repository navigation
HMAC.copy() does not correctly copy its attributes #142451
Description
Activity
- addedtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
on Dec 9, 2025 - addedextension-modulesC modules in the Modules dirC modules in the Modules dir
on Dec 9, 2025 macos works fine
python3.14 works fine
it happens in linux main
errror
Traceback (most recent call last): File "/home/yihong/cpython/ttt.py", line 6, in <module> print(h_copy.name) ^^^^^^^^^^^ File "/home/yihong/cpython/Lib/hmac.py", line 157, in name return self._hmac.name ^^^^^^^^^^^^^^^ ValueError: [object identifier routines] unknown nidseems with openssl problen
yihong@ubuntu:~/cpython$ openssl version
OpenSSL 3.3.1 4 Jun 2024 (Library: OpenSSL 3.3.1 4 Jun 2024)OK, I know the issue. I forgot to copy the
evp_md_nidinhmac.copyso it get initialized to 0, which leads to a crash. Thanks for catching this!Note: I'm actually surprised that the error indicator is not set in this case, because it goes against OpenSSL docs actually:
OBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID n to an ASN1_OBJECT structure, its long name and its short name respectively, or NULL if an error occurred.
Reacted by yihongSo actually we have two issues:
- On some OpenSSL versions it seems that
OBJ_nid2objmay return NULL without an error indicator set (which is a bit weird though but I guess I can also remove the assertion, it could have been a too strict guard). - The copy is lacking the NID because I forgot to copy the field as well...
Reacted by yihong- On some OpenSSL versions it seems that
So actually we have two issues:
- On some OpenSSL versions it seems that
OBJ_nid2objmay return NULL without an error indicator set (which is a bit weird though but I guess I can also remove the assertion, it could have been a too strict guard). - The copy is lacking the NID because I forgot to copy the field as well...
yes different OpenSSL version behavior
- On some OpenSSL versions it seems that
Thank you for the report!
- changed the title
[-]Assertion failure at Modules/_hashopenssl.c:610 `const char *get_asn1_utf8name_by_nid(int): Assertion 'ERR_peek_last_error() != 0' failed.`[/-][+]HMAC.copy() does not correctly copy its attributes[/+]on Dec 14, 2025 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directoryand removed3.15bugs and security fixesbugs and security fixes
on Dec 14, 2025 I'm going to re-use this issue for the lack of
block_sizeinHMAC.copyas well.- added 4 commits that reference this issue
on Dec 14, 2025
Crash report
What happened?
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Output from running 'python -VV' on the command line:
No response
Linked PRs
HMAC.copy()#142510HMAC.copy()(GH-142510) #142698HMAC.copy()(GH-142510) #142701