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

Python 3.9 regression: Literal dict with > 65535 items are one item shorter #85703

Closed
hroncok mannequin opened this issue Aug 12, 2020 · 9 comments
Closed

Python 3.9 regression: Literal dict with > 65535 items are one item shorter #85703

hroncok mannequin opened this issue Aug 12, 2020 · 9 comments
Labels
3.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error

Comments

@hroncok
Copy link
Mannequin

hroncok mannequin commented Aug 12, 2020

BPO 41531
Nosy @ericvsmith, @markshannon, @serhiy-storchaka, @hroncok, @pablogsal, @miss-islington, @tirkarthi
PRs
  • bpo-41531: Fix compilation of dict literals with more than 0xFFFF elements #21850
  • [3.9] bpo-41531: Fix compilation of dict literals with more than 0xFFFF elements (GH-21850) #21853
  • [3.9] bpo-41531: Fix compilation of dict literals with more than 0xFFFF elements (GH-21850) #22105
  • [3.9] bpo-41531: Fix compilation of dict literals with more than 0xFFFF elements (GH-21850) #22107
  • 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 = None
    closed_at = <Date 2020-09-04.23:39:20.850>
    created_at = <Date 2020-08-12.15:42:56.845>
    labels = ['interpreter-core', 'type-bug', '3.9', '3.10', 'release-blocker']
    title = 'Python 3.9 regression: Literal dict with > 65535 items are one item shorter'
    updated_at = <Date 2020-09-04.23:39:20.849>
    user = 'https://github.com/hroncok'

    bugs.python.org fields:

    activity = <Date 2020-09-04.23:39:20.849>
    actor = 'pablogsal'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-09-04.23:39:20.850>
    closer = 'pablogsal'
    components = ['Interpreter Core']
    creation = <Date 2020-08-12.15:42:56.845>
    creator = 'hroncok'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 41531
    keywords = ['patch', '3.9regression']
    message_count = 9.0
    messages = ['375255', '375256', '375257', '375259', '375275', '375295', '375296', '375297', '376417']
    nosy_count = 10.0
    nosy_names = ['eric.smith', 'mrabarnett', 'zbysz', 'Mark.Shannon', 'serhiy.storchaka', 'hroncok', 'pablogsal', 'miss-islington', 'xtreak', 'batuhanosmantaskaya']
    pr_nums = ['21850', '21853', '22105', '22107']
    priority = 'release blocker'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue41531'
    versions = ['Python 3.9', 'Python 3.10']

    @hroncok
    Copy link
    Mannequin Author

    hroncok mannequin commented Aug 12, 2020

    Consider this reproducer.py:

    import sys
    LEN = int(sys.argv[1])
    
    with open('big_dict.py', 'w') as f:
        print('INTS = {', file=f)
        for i in range(LEN):
            print(f'    {i}: None,', file=f)
        print('}', file=f)
    
    
    import big_dict
    assert len(big_dict.INTS) == LEN, len(big_dict.INTS)

    And run it with any number > 65535:

    $ python3.9 reproducer.py 65536
    Traceback (most recent call last):
      File "/tmp/reproducer.py", line 12, in <module>
        assert len(big_dict.INTS) == LEN, len(big_dict.INTS)
    AssertionError: 65535

    This has not happened on python 3.8. This also happens with PYTHONOLDPARSER=1.

    @hroncok hroncok mannequin added 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Aug 12, 2020
    @zbysz
    Copy link
    Mannequin

    zbysz mannequin commented Aug 12, 2020

    Also reproduces with today's git.

    @hroncok
    Copy link
    Mannequin Author

    hroncok mannequin commented Aug 12, 2020

    It appears that the 65535 key is missing regardless of the LEN value.

    @zbysz
    Copy link
    Mannequin

    zbysz mannequin commented Aug 12, 2020

    Bisect says 8a4cd70 is the first bad commit. Considering that 0xFFFF appears a few times in that patch, that seems plausible ;)

    @hroncok hroncok mannequin added 3.10 only security fixes labels Aug 12, 2020
    @serhiy-storchaka serhiy-storchaka added interpreter-core (Objects, Python, Grammar, and Parser dirs) labels Aug 12, 2020
    @mrabarnett
    Copy link
    Mannequin

    mrabarnett mannequin commented Aug 12, 2020

    I think what's happening is that in 'compiler_dict' (Python/compile.c), it's checking whether 'elements' has reached a maximum (0xFFFF). However, it's not doing this after incrementing; instead, it's checking before incrementing and resetting 'elements' to 0 when it should be resetting to 1. The 65535th element isn't counted.

    @markshannon
    Copy link
    Member

    New changeset c51db0e by Pablo Galindo in branch 'master':
    bpo-41531: Fix compilation of dict literals with more than 0xFFFF elements (GH-21850)
    c51db0e

    @markshannon
    Copy link
    Member

    @hroncok,

    How did you discover this issue?

    I'd like to clean up the code for creating dictionary literals and it might be helpful to know where such huge dictionary literals exist.
    I'm guessing that they are used as lookup tables for things like Unicode code-point tables, and that they would only include constants.

    @tirkarthi
    Copy link
    Member

    @hroncok said on Twitter it was reported at Storyyeller/enjarify#17

    @pablogsal
    Copy link
    Member

    New changeset d64d78b by Miss Islington (bot) in branch '3.9':
    bpo-41531: Fix compilation of dict literals with more than 0xFFFF elements (GH-21850) (GH-22107)
    d64d78b

    @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.9 only security fixes 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) release-blocker type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants