Repository navigation
gh-159786: Convert HACL* update() errors in _hmac after releasing the lock - #159805
Merged
gpshead merged 2 commits intoOct 20, 2026
Merged
Conversation
…sing the lock `_hacl_hmac_state_update_once()` converted the HACL* exit code into an exception while the thread state was detached and, for HMAC.update(), while the object's mutex was held. On debug builds, this re-attached the thread state under the mutex and then called PyErr_Occurred() with the thread state detached in the chunking loop of `_hacl_hmac_state_update()`. Return the raw HACL* exit code instead and convert it in `_hmac.new()` and `_hmac.HMAC.update()` once the thread state is re-attached and the mutex is released, as `hmac_digest_compute_locked()` already does. Release builds keep ignoring the update() exit code. Since `_hacl_convert_errno()` is now always called with an attached thread state, remove the `PyGILState_Ensure()` added by pythongh-135561 and assert that a thread state is attached instead.
gpshead
approved these changes
Oct 19, 2026
gpshead
left a comment
Member
There was a problem hiding this comment.
I added a commit... lets also simplify and always check for the error regardless of debug build or not.
|
GH-159825 is a backport of this pull request to the 3.15 branch. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_hacl_hmac_state_update_once()converted the HACL* exit code into an exception while the thread state was detached and, for HMAC.update(), while the object's mutex was held. On debug builds, this re-attached the thread state under the mutex and then called PyErr_Occurred() with the thread state detached in the chunking loop of_hacl_hmac_state_update().Return the raw HACL* exit code instead and convert it in
_hmac.new()and_hmac.HMAC.update()once the thread state is re-attached and the mutex is released, ashmac_digest_compute_locked()already does. Release builds now also check for the error making for far simpler code. The actual trigger for an error from hacl was an unrealistically large data size.Since
_hacl_convert_errno()is now always called with an attached thread state, remove thePyGILState_Ensure()added by gh-135561 and assert that a thread state is attached instead.update()errors are handled without a thread state #159786