Skip to content

Ensure that HMAC objects are properly initialized #155843

Closed

Description

@picnixz

Bug report

Bug description:

This affects the following situations:

  • _hmac.new() frees an uninitialized HACL pointer when the key exceeds UINT32_MAX
  • _hmac_HMAC_copy_impl runs HASHLIB_INIT_MUTEX(copy) after the fallible hmac_copy_state

The solution is simply to always entirely initialize the HMAC object before working with it. We also change the usage of PyObject_New to tp->tp_alloc directly so that we only alter fields for which the 0-value would not be suitable.

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Linked PRs

Activity

  1. self-assigned this
    on Aug 15, 2026
  2. added a commit that references this issue on Sep 6, 2026
  3. added a commit that references this issue on Sep 12, 2026
  4. added a commit that references this issue on Oct 12, 2026
  5. added a commit that references this issue on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

extension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions