]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-146287: Fix signed/unsigned mismatch in _hashlib_hmac_digest_size (GH-148407)
authorGregory P. Smith <68491+gpshead@users.noreply.github.com>
Sun, 12 Apr 2026 00:02:56 +0000 (17:02 -0700)
committerGitHub <noreply@github.com>
Sun, 12 Apr 2026 00:02:56 +0000 (00:02 +0000)
commitd761f539bdae6090817438ae65c0be8a10c9e4e3
tree38c917e1c1b07cda80616c95aaeabbffbe7c3cbc
parentcef334fd4c4c24a542ce81ad940b1426b5a7cdbd
gh-146287: Fix signed/unsigned mismatch in _hashlib_hmac_digest_size (GH-148407)

* gh-146287: use signed type for HMAC digest size to prevent unsigned wrapping

Change _hashlib_hmac_digest_size() return type from unsigned int to int
so that a hypothetical negative return from EVP_MD_size() is not
silently wrapped to a large positive value. Add an explicit check for
negative digest_size in the legacy OpenSSL path, and use SystemError
(not ValueError) since these conditions indicate internal invariant
violations. Also add debug-build asserts to EVP_get_block_size and
EVP_get_digest_size documenting that the hash context is always
initialized.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Modules/_hashopenssl.c