Skip to content

dict creation failure causes crash #47787

Closed

Description

@rupole
mannequin
BPO 3537
Nosy @birkenfeld
Files
  • dictobj.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 = None
    closed_at = <Date 2008-08-11.09:08:20.398>
    created_at = <Date 2008-08-10.18:10:23.645>
    labels = []
    title = 'dict creation failure causes crash'
    updated_at = <Date 2008-08-11.09:08:20.380>
    user = 'https://bugs.python.org/rupole'

    bugs.python.org fields:

    activity = <Date 2008-08-11.09:08:20.380>
    actor = 'georg.brandl'
    assignee = 'none'
    closed = True
    closed_date = <Date 2008-08-11.09:08:20.398>
    closer = 'georg.brandl'
    components = []
    creation = <Date 2008-08-10.18:10:23.645>
    creator = 'rupole'
    dependencies = []
    files = ['11095']
    hgrepos = []
    issue_num = 3537
    keywords = ['patch']
    message_count = 4.0
    messages = ['70990', '70991', '70992', '71004']
    nosy_count = 2.0
    nosy_names = ['georg.brandl', 'rupole']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue3537'
    versions = ['Python 2.6', 'Python 3.0']

    Activity

    1. rupole commented on Aug 10, 2008

      rupolemannequin
      MannequinAuthor

      If the first item can't be inserted the interpreter will crash
      eventually.

      while 1:
      	try:
      		d = { 'a':a,
      		  'b':'b',
      		  'c':'c',
      		  'd':'d',
      		  'e':'e',
      		  'f':'f',
      		  'g':'g',
      		  'h':'h',
      		  'i':'i',
      		  'j':'j',
      		  'k':'k',
      		  'l':'l',
      		  'm':'m',
      		  'n':'n',
      		  'o':'o'
      		  }
      	except:
      		pass

      As best I can tell, this only happens for the first item.
      In a debug build, this assert fails on the second time thru
      the loop (dictobject.c, line 247):
      assert (mp->ma_table == mp->ma_smalltable);

      Apparently something is leaving one of the entries in the list
      of preallocated dict objects in an inconsistent state.

    2. birkenfeld commented on Aug 10, 2008

      @birkenfeld
      Member

      Also happens in trunk.

    3. birkenfeld commented on Aug 10, 2008

      @birkenfeld
      Member

      The problem is that PyDict_New doesn't reinitialize the fields of a dict
      from the free list when the number of entries is zero. For a
      preconstructed dict (like created by BUILD_MAP) of size >=8, however,
      there will be an allocated ma_table and ma_mask will be 16-1, not 8-1.

      I propose the attached patch.

    4. birkenfeld commented on Aug 11, 2008

      @birkenfeld
      Member

      Applied and added test in r65637.

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      No labels
      No labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions