Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hashlib does not handle missing hash functions correctly #56268

Closed
ianw mannequin opened this issue May 11, 2011 · 2 comments
Closed

hashlib does not handle missing hash functions correctly #56268

ianw mannequin opened this issue May 11, 2011 · 2 comments
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@ianw
Copy link
Mannequin

ianw mannequin commented May 11, 2011

BPO 12059
Nosy @gpshead, @ianw
Files
  • hashlib.py.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/gpshead'
    closed_at = <Date 2011-05-14.22:37:13.635>
    created_at = <Date 2011-05-11.18:59:08.557>
    labels = ['type-bug']
    title = 'hashlib does not handle missing hash functions correctly'
    updated_at = <Date 2011-05-14.22:37:13.634>
    user = 'https://github.com/ianw'

    bugs.python.org fields:

    activity = <Date 2011-05-14.22:37:13.634>
    actor = 'gregory.p.smith'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2011-05-14.22:37:13.635>
    closer = 'gregory.p.smith'
    components = []
    creation = <Date 2011-05-11.18:59:08.557>
    creator = 'iwienand'
    dependencies = []
    files = ['21971']
    hgrepos = []
    issue_num = 12059
    keywords = ['patch']
    message_count = 2.0
    messages = ['135794', '135999']
    nosy_count = 3.0
    nosy_names = ['gregory.p.smith', 'python-dev', 'iwienand']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue12059'
    versions = ['Python 2.6', 'Python 2.7']

    @ianw
    Copy link
    Mannequin Author

    ianw mannequin commented May 11, 2011

    If one of the hash functions isn't defined in _hashlib, the code suggests it should just be skipped

    ===
    # this one has no builtin implementation, don't define it
    pass
    ===

    This doesn't happen however; due to ImportError not being caught the module decides the whole _hashlib module isn't available and tries to fall back to the older individual libraries. You then get thrown an unrelated error about _md5 being unavailable

    You can easily replicate this

    ---

    $ python
    Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) 
    [GCC 4.4.5] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> def foo():
    ...     raise ValueError
    ... 
    >>> import _hashlib
    >>> _hashlib.openssl_sha224 = foo
    >>> import hashlib
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python2.6/hashlib.py", line 136, in <module>
        md5 = __get_builtin_constructor('md5')
      File "/usr/lib/python2.6/hashlib.py", line 63, in __get_builtin_constructor
        import _md5
    ImportError: No module named _md5
    >>> 

    I think the solution is to catch the ImportError in __get_builtin_constructor and, if caught, consider the hash function unsupported

    @ianw ianw mannequin added the type-bug An unexpected behavior, bug, or error label May 11, 2011
    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 14, 2011

    New changeset 572fbd9ca28f by Gregory P. Smith in branch '2.7':
    Fixes Issue bpo-12059: Properly handle missing hash functions even when
    http://hg.python.org/cpython/rev/572fbd9ca28f

    New changeset ad9249f35914 by Gregory P. Smith in branch '3.2':
    Fixes Issue bpo-12059: Properly handle missing hash functions even when
    http://hg.python.org/cpython/rev/ad9249f35914

    New changeset 298888fd46b0 by Gregory P. Smith in branch 'default':
    Fixes Issue bpo-12059: Properly handle missing hash functions even when
    http://hg.python.org/cpython/rev/298888fd46b0

    @gpshead gpshead closed this as completed May 14, 2011
    @gpshead gpshead self-assigned this May 14, 2011
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant