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 — HACL* `update()` errors are handled without a thread state · Issue #159786 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
HACL* update() errors are handled without a thread state#159786
Copy link
Assignees
picnixz
Labels
3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@picnixz
picnixz
opened on Oct 19, 2026
Issue body actions

Bug report

gh-135561 made _hacl_convert_errno() attach a thread state with PyGILState_Ensure() before setting an exception, because it may be called while the GIL is released. Since gh-135239, _hacl_hmac_state_update_once() calls _hacl_convert_errno() from inside HASHLIB_EXTERNAL_INSTRUCTIONS_UNLOCKED (in _hmac.new()) and HASHLIB_EXTERNAL_INSTRUCTIONS_LOCKED (in _hmac.HMAC.update()).

The following issues arise on DEBUG builds:

  1. If a chunk fails in the chunking loop of _hacl_hmac_state_update(), the loop then runs assert(PyErr_Occurred()). By that point, _hacl_convert_errno() has already called PyGILState_Release(), so PyErr_Occurred() runs without an attached thread state. The loop only runs for buffers larger than UINT32_MAX bytes.
  2. In _hmac.HMAC.update(), PyGILState_Ensure() runs while self->mutex is held, so a thread state is attached while the object's lock is held.

In practice, you need a HACL* update() failure such as MaximumLengthExceeded, and release builds ignore the HACL* exit code of update() anyway. However, since I wrote the module with DEBUG builds in mind just in case, I still want to cover that case.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

  • gh-159786: Convert HACL* update() errors in _hmac after releasing the lock #159805
  • [3.15] gh-159786: Convert HACL* update() errors in _hmac after releasing the lock (GH-159805) #159825

Activity

  1. picnixz
    self-assigned this
    on Oct 19, 2026
  2. picnixz
    added a parent issue on Oct 19, 2026
    • Meta-issue for bugs in cryptographic extension modules #155438
  3. picnixz
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    3.15bugs and security fixesbugs and security fixes
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    on Oct 19, 2026
  4. picnixz
    added 3 commits that reference this issue on Oct 19, 2026

    pythongh-159786: Convert HACL* update() errors in `_hmac` after relea…

    9df8c74

    pythongh-159786: Convert HACL* update() errors in `_hmac` after relea…

    6870478

    pythongh-159786: Convert HACL* update() errors in `_hmac` after relea…

    e81a055
  5. gpshead
    added a commit that references this issue on Oct 20, 2026

    gh-159786: Convert HACL* update() errors in `_hmac` after releasing t…

    0fba211
  6. picnixz
    added a commit that references this issue on Oct 20, 2026

    [3.15] gh-159786: Convert HACL* update() errors in `_hmac` after rele…

    4250c67
  7. hugovk
    closed this as completedon Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @picnixz
    picnixz

Labels

3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.