You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HMAC.copy() does not correctly copy its attributes #142451
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 nid
seems 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_nid in hmac.copy so 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.
On some OpenSSL versions it seems that OBJ_nid2obj may 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...
On some OpenSSL versions it seems that OBJ_nid2obj may 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...
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
Activity
yihong0618 commentedon Dec 9, 2025
macos works fine
python3.14 works fine
it happens in linux main
errror
seems with openssl problen
yihong@ubuntu:~/cpython$ openssl version
OpenSSL 3.3.1 4 Jun 2024 (Library: OpenSSL 3.3.1 4 Jun 2024)
yihong0618 commentedon Dec 9, 2025
bisect this commit bring this issue
cc @picnixz
b9c50b4
picnixz commentedon Dec 9, 2025
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:
picnixz commentedon Dec 9, 2025
So actually we have two issues:
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).yihong0618 commentedon Dec 10, 2025
yes different OpenSSL version behavior
pythongh-142451: correctly copy HMAC attributes in `HMAC.copy()`
gh-142451: correctly copy HMAC attributes in `HMAC.copy()` (#142510)
picnixz commentedon Dec 14, 2025
Thank you for the report!
[-]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[/+]picnixz commentedon Dec 14, 2025
I'm going to re-use this issue for the lack of
block_sizeinHMAC.copyas well.pythongh-142451: correctly copy `HMAC.block_size` attribute
pythongh-142451: correctly copy `HMAC.block_size` attribute
[3.14] gh-142451: correctly copy HMAC attributes in `HMAC.copy()` (GH…
[3.13] gh-142451: correctly copy HMAC attributes in `HMAC.copy()` (GH…
pythongh-142451: correctly copy HMAC attributes in `HMAC.copy()` (pyt…