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

Internal Random class calling seed() with incorrect argument #86174

Closed
rhettinger opened this issue Oct 11, 2020 · 4 comments
Closed

Internal Random class calling seed() with incorrect argument #86174

rhettinger opened this issue Oct 11, 2020 · 4 comments
Assignees
Labels
3.10 only security fixes easy extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error

Comments

@rhettinger
Copy link
Contributor

BPO 42008
Nosy @rhettinger, @amiremohamadi
PRs
  • bpo-42008: Fix _random.Random() seeding #22668
  • 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/rhettinger'
    closed_at = <Date 2020-12-21.23:46:42.217>
    created_at = <Date 2020-10-11.21:52:41.471>
    labels = ['extension-modules', 'easy', 'type-bug', '3.10']
    title = 'Internal Random class calling seed() with incorrect argument'
    updated_at = <Date 2020-12-21.23:46:42.216>
    user = 'https://github.com/rhettinger'

    bugs.python.org fields:

    activity = <Date 2020-12-21.23:46:42.216>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = <Date 2020-12-21.23:46:42.217>
    closer = 'rhettinger'
    components = ['Extension Modules']
    creation = <Date 2020-10-11.21:52:41.471>
    creator = 'rhettinger'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 42008
    keywords = ['patch', 'easy (C)']
    message_count = 4.0
    messages = ['378457', '378482', '383561', '383562']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'Amir']
    pr_nums = ['22668']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue42008'
    versions = ['Python 3.10']

    @rhettinger
    Copy link
    Contributor Author

    The C code in random_new() incorrectly calls random_seed() with an args tuple. Instead, it should use first element of the args tuple.

    This matters because we've deprecated using PyObject_Hash() in random_seed(). Once that is removed, _random.Random(someseed) won't work at all (there's a test for it).

    # Public API is correct
    >>> from random import Random
    >>> r = Random()
    >>> r.seed(8675309)
    >>> r.random()
    0.40224696110279223
    >>> r = Random(8675309)
    >>> r.random()
    0.40224696110279223
    
    # Private API is incorrect for Random(someseed)
    >>> from _random import Random
    >>> r = Random()
    >>> r.seed(8675309)
    >>> r.random()
    0.40224696110279223
    >>> r = Random(8675309)              
    >>> r.random()
    0.21095576307886765                  <=== This is wrong

    @rhettinger rhettinger added 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes extension-modules C modules in the Modules dir easy type-bug An unexpected behavior, bug, or error labels Oct 11, 2020
    @amiremohamadi
    Copy link
    Mannequin

    amiremohamadi mannequin commented Oct 12, 2020

    Can I open a PR for it?

    @rhettinger
    Copy link
    Contributor Author

    New changeset b8fde8b by AMIR in branch 'master':
    bpo-42008: Fix internal _random.Random() seeding for the one argument case (GH-22668)
    b8fde8b

    @rhettinger
    Copy link
    Contributor Author

    Thanks for the PR :-)

    @rhettinger rhettinger removed 3.8 only security fixes 3.9 only security fixes labels Dec 21, 2020
    @rhettinger rhettinger self-assigned this Dec 21, 2020
    @rhettinger rhettinger removed 3.8 only security fixes 3.9 only security fixes labels Dec 21, 2020
    @rhettinger rhettinger self-assigned this Dec 21, 2020
    @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
    3.10 only security fixes easy extension-modules C modules in the Modules dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant