GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-159786: Convert HACL* update() errors in `_hmac` after releasing the lock by picnixz · Pull Request #159805 · python/cpython

Conversation

@picnixz

@picnixz picnixz commented Oct 19, 2026 •
edited by gpshead
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

_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 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 the PyGILState_Ensure() added by gh-135561 and assert that a thread state is attached instead.

  • Issue: HACL* update() errors are handled without a thread state #159786

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@picnixz
pythongh-159786: Convert HACL* update() errors in _hmac after relea…
e81a055
…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.
@picnixz
picnixz requested a review from gpshead as a code owner October 19, 2026 22:37
@bedevere-app bedevere-app Bot mentioned this pull request Oct 19, 2026
HACL* update() errors are handled without a thread state #159786
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Oct 19, 2026
@picnixz picnixz added the needs backport to 3.15 bugs and security fixes label Oct 19, 2026
@gpshead
simplify ifdefs: always check for the hacl error
d18d73f
gpshead
gpshead approved these changes Oct 19, 2026
View reviewed changes

@gpshead gpshead left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a commit... lets also simplify and always check for the error regardless of debug build or not.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Oct 19, 2026
@picnixz picnixz added the sprint label Oct 20, 2026
@github-project-automation github-project-automation Bot added this to Sprint Oct 20, 2026
@picnixz picnixz self-assigned this Oct 20, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Oct 20, 2026
@github-project-automation github-project-automation Bot moved this from Todo to In Progress in Sprint Oct 20, 2026
@gpshead
gpshead merged commit 0fba211 into python:main Oct 20, 2026
62 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Oct 20, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Sprint Oct 20, 2026
@miss-islington-app

miss-islington-app Bot commented Oct 20, 2026

Copy link
Copy Markdown

Thanks @picnixz for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app

bedevere-app Bot commented Oct 20, 2026

Copy link
Copy Markdown

GH-159825 is a backport of this pull request to the 3.15 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Oct 20, 2026
@picnixz
picnixz deleted the meta/crypto/c/hmac/33-45/gil-issue-159786 branch October 20, 2026 13:01
picnixz added a commit that referenced this pull request Oct 20, 2026
@miss-islington @picnixz @gpshead
[3.15] gh-159786: Convert HACL* update() errors in _hmac after rele…
4250c67
…asing the lock (GH-159805) (#159825)

gh-159786: Convert HACL* update() errors in `_hmac` after releasing the lock (GH-159805)

* gh-159786: Convert HACL* update() errors in `_hmac` after releasing 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 gh-135561 and
assert that a thread state is attached instead.

* simplify ifdefs: always check for the hacl error

---------
(cherry picked from commit 0fba211)

Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: Gregory P. Smith <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@gpshead gpshead gpshead approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@picnixz picnixz

Labels

sprint

Projects

Sprint
Archived in project

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@picnixz @gpshead
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.