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 — `_hashlib`: GIL may be released while attempting to set an exception · Issue #159811 · python/cpython

_hashlib: GIL may be released while attempting to set an exception #159811

New issue
Copy link
New issue
Copy link
Closed
Closed
_hashlib: GIL may be released while attempting to set an exception#159811
Copy link
Assignees
picnixz
Labels
extension-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

_hashlib calls notify_ssl_error_occurred_in() and notify_smart_ssl_error_occurred_in() inside HASHLIB_EXTERNAL_INSTRUCTIONS_{LOCKED,UNLOCKED} blocks, that is, while the thread
state is detached (and, for the LOCKED variant, while the object's mutex is held).

These helpers call PyErr_* functions; thus, if the libssl's update function fails on a buffer larger than HASHLIB_GIL_MINSIZE, the interpreter crashes instead of raising a ValueError:

  • _hashlib.HASH.update(): _hashlib_HASH_hash() raises when EVP_DigestUpdate() fails.
  • _hashlib.new() and the named constructors (e.g. _hashlib.openssl_sha256(data)): same helper, called on the initial data.
  • _hashlib.HMAC.update() and _hashlib.hmac_new(): hashlib_openssl_HMAC_update_once() raises when EVP_MAC_update() (or HMAC_Update()) fails. This one is a regression introduced by Port HMAC implementation to new OpenSSL APIs #134531. On 3.14, the exception was raised after the GIL was re-acquired.

Note that the default OpenSSL provider never fails in these update functions. This is solely to protect provides that can fail. For buffers of at most 2048 bytes (GIL held), the same failure correctly raises a ValueError.

The same class of bug was fixed in _hmac by gh-135561 and gh-159786. The fix here is the same: report the libssl error after the thread state is re-attached and the lock is released. The OpenSSL error queue is per OS thread, so the message is preserved.

  • The HASH constructor and update() paths are affected on 3.13 and later.
  • The HMAC path is affected since 3.15.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

  • gh-159811: Raise OpenSSL errors in _hashlib.HASH after re-attaching the thread state #159817
  • [3.15] gh-159811: Raise OpenSSL errors in _hashlib.HASH after re-attaching the thread state (GH-159817) #159927
  • gh-159811: Raise OpenSSL errors in _hashlib.HMAC after re-attaching the thread state #159818
  • [3.15] gh-159811: Raise OpenSSL errors in _hashlib.HMAC after re-attaching the thread state (GH-159818) #159926
  • [3.14] gh-159811: Raise OpenSSL errors in _hashlib.HASH after re-attaching the thread state (GH-159817) #159937

Activity

  1. picnixz
    self-assigned this
    on Oct 19, 2026
  2. picnixz
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 19, 2026
  3. picnixz
    added a parent issue on Oct 19, 2026
    • Meta-issue for bugs in cryptographic extension modules #155438
  4. picnixz
    added
    extension-modulesC modules in the Modules dirC modules in the Modules dir
    on Oct 19, 2026
  5. picnixz
    added 6 commits that reference this issue on Oct 20, 2026

    pythongh-159811: Raise OpenSSL errors in `_hashlib.HMAC` after re-att…

    060abbf

    gh-159811: Raise OpenSSL errors in `_hashlib.HMAC` after re-attaching…

    b4b81e1

    gh-159811: Raise OpenSSL errors in `_hashlib.HASH` after re-attaching…

    6fa2d64

    [3.15] gh-159811: Raise OpenSSL errors in `_hashlib.HMAC` after re-at…

    3421009

    [3.14] gh-159811: Raise OpenSSL errors in `_hashlib.HASH` after re-at…

    5eed22f

    [3.15] gh-159811: Raise OpenSSL errors in `_hashlib.HASH` after re-at…

    0405f10
  6. picnixz
    closed this as completedon Oct 20, 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

extension-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 01402520 — 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.