FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve `_hashlib` exception reporting when an OpenSSL error occurred · Issue #135234 · python/cpython · GitHub

Repository navigation

Improve _hashlib exception reporting when an OpenSSL error occurred #135234

Closed

Description

OpenSSL memory allocation failures

When an OpenSSL error occurs, we usually raise a ValueError. However, failures may be related to malloc(), in which case we should raise a MemoryError as we usually do. I have a PR ready for this.

Incorrect usage of get_openssl_evp_md_by_utf8name()

In get_openssl_evp_md_by_utf8name, when we pass an incorrect Py_hash_type or a digest that we cannot find, we raise:

    raise_ssl_error(state->unsupported_digestmod_error,
                    "unsupported hash type %s", name);

The "unsupported hash type %s" message only happens if no SSL error occurred during the execution, and this only happens if we pass an incorrect Py_hash_type, which also only happens "internally". So we should correctly report that the issue is with the Py_hash_type argument, not with the named argument.

Note: The raise_ssl_error function is a function that raises an automatically formatted message if there is an OpenSSL error or raises the "alternative" error message. But in this case, we should probably separate the exception and raise an SystemError / Py_UNREACHABLE() if we pass a wrong Py_hash_type (strictly speaking, it shouldn't be possible because the compiler would have complained if we pass an arbitrary integer as Py_hash_type is an enum).

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

This is related to the work I did in #134531.

Linked PRs

Activity

  1. self-assigned this
    on Jun 7, 2025
  2. changed the title [-]Raise MemoryError instead of ValueError when OpenSSL malloc() failed[/-] [+]Improve `_hashlib` exception reporting when an OpenSSL error occurred[/+] on Jun 7, 2025
  3. added a commit that references this issue on Jun 9, 2025
  4. added a commit that references this issue on Jun 19, 2025
  5. added a commit that references this issue on Jul 12, 2025
  6. added a commit that references this issue on Aug 4, 2025
  7. added a commit that references this issue on Aug 19, 2025
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-featureA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL