Skip to content

Problem with recursion in dict (crash with core dump) #41979

Closed

Description

@vys
mannequin
BPO 1201456
Nosy @mwhudson, @rhettinger, @josiahcarlson, @ncoghlan

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 2005-05-23.04:46:32.000>
created_at = <Date 2005-05-13.15:43:19.000>
labels = ['interpreter-core']
title = 'Problem with recursion in dict (crash with core dump)'
updated_at = <Date 2005-05-23.04:46:32.000>
user = 'https://bugs.python.org/vys'

bugs.python.org fields:

activity = <Date 2005-05-23.04:46:32.000>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Interpreter Core']
creation = <Date 2005-05-13.15:43:19.000>
creator = 'vys'
dependencies = []
files = []
hgrepos = []
issue_num = 1201456
keywords = []
message_count = 10.0
messages = ['25301', '25302', '25303', '25304', '25305', '25306', '25307', '25308', '25309', '25310']
nosy_count = 5.0
nosy_names = ['mwh', 'rhettinger', 'josiahcarlson', 'ncoghlan', 'vys']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1201456'
versions = ['Python 2.4']

Activity

  1. vys commented on May 13, 2005

    vysmannequin
    MannequinAuthor

    Please see example code.

  2. added
    interpreter-core
    on May 13, 2005
  3. added
    interpreter-core
    on May 13, 2005
  4. mwhudson commented on May 13, 2005

    @mwhudson

    Logged In: YES
    user_id=6656

    I see no code. SF can be a pain with this...

  5. vys commented on May 13, 2005

    vysmannequin
    MannequinAuthor

    Logged In: YES
    user_id=384980

    d = {} 
     
    class test: 
            def __hash__(self): 
                    d[self] = None 
     
    d[test()] = None
  6. mwhudson commented on May 13, 2005

    @mwhudson

    Logged In: YES
    user_id=6656

    I get an infinite recursion runtime error. What platform
    are you on?

  7. rhettinger commented on May 13, 2005

    @rhettinger
    Contributor

    Logged In: YES
    user_id=80475

    I get the expected behavior:

    RuntimeError: maximum recursion depth exceeded

  8. vys commented on May 13, 2005

    vysmannequin
    MannequinAuthor

    Logged In: YES
    user_id=384980

    This is output from `uname -a`: 
    FreeBSD fox.renet.ru 5.3-RELEASE FreeBSD 5.3-RELEASE 
    #1: Fri Apr 15 10:38:49 MSD 2005     
    root@fox.renet.ru:/M/safedir/src/sys/i386/compile/FOX  i386 
     
    I get some others with this code: 
     
    Python 2.4.1 (#2, Apr 26 2005, 14:16:31) 
    [GCC 3.4.2 [FreeBSD] 20040728] on freebsd5 
    Type "help", "copyright", "credits" or "license" for more 
    information. 
    >>> d = {} 
    >>> 
    >>> class test: 
    ...         def __hash__(self): 
    ...                 d[self] = None 
    ... 
    >>> d[test()] = None 
    Bus error (core dumped) 
     
     
    fox:vys!~ > gdb python python.core 
    GNU gdb 6.1.1 [FreeBSD] 
    Copyright 2004 Free Software Foundation, Inc. 
    GDB is free software, covered by the GNU General Public 
    License, and you are 
    welcome to change it and/or distribute copies of it under 
    certain conditions. 
    Type "show copying" to see the conditions. 
    There is absolutely no warranty for GDB.  Type "show 
    warranty" for details. 
    This GDB was configured as "i386-marcel-freebsd"...(no 
    debugging symbols found)... 
    Core was generated by `python'. 
    Program terminated with signal 10, Bus error. 
    <skip> 
    (gdb) where 
    #0  0x2828b3b1 in ldexp () from /lib/libc.so.5 
    #1  0x2828b618 in malloc () from /lib/libc.so.5 
    #2  0x080bdca1 in _PyObject_GC_Malloc () 
    #3  0x080bdd4a in _PyObject_GC_New () 
    #4  0x0805f556 in PyMethod_New () 
    #5  0x0805c1a6 in PyInstance_NewRaw () 
    #6  0x0805c66a in PyInstance_New () 
    #7  0x0805cca1 in _PyInstance_Lookup () 
    #8  0x080703e6 in PyDict_SetItem () 
    #9  0x0809bb0e in PyEval_EvalFrame () 
    #10 0x0809fc20 in PyEval_EvalCodeEx () 
    #11 0x080d4d66 in PyFunction_SetClosure () 
    #12 0x0805a38c in PyObject_Call () 
    #13 0x0805fbe2 in PyMethod_New () 
    #14 0x0805a38c in PyObject_Call () 
    #15 0x08099f1b in PyEval_CallObjectWithKeywords () 
    #16 0x0805ccb9 in _PyInstance_Lookup () 
    #17 0x080703e6 in PyDict_SetItem () 
    #18 0x0809bb0e in PyEval_EvalFrame () 
    #19 0x0809fc20 in PyEval_EvalCodeEx () 
    #20 0x080d4d66 in PyFunction_SetClosure () 
    #21 0x0805a38c in PyObject_Call () 
    #22 0x0805fbe2 in PyMethod_New () 
    <and so on>
  9. ncoghlan commented on May 18, 2005

    @ncoghlan
    Contributor

    Logged In: YES
    user_id=1038590

    What does sys.getrecursionlimit() return?

    Does the buggy code generate the expected exception if you
    use sys.setrecursionlimit() to make the value smaller (e.g.
    500)?

    FreeBSD has a history of not playing well with CPython's
    ability to detect inifinite recursion. . .

  10. vys commented on May 18, 2005

    vysmannequin
    MannequinAuthor

    Logged In: YES
    user_id=384980

    sys.getrecursionlimit() returns 1000.
    I set sys.setrecursionlimit() to 500 and problem was resolved :)

    Thank you very much !

    PS. Is it possible to add some checks in Py_SetRecursionLimit
    to reject overflow values ?

  11. josiahcarlson commented on May 23, 2005

    josiahcarlsonmannequin
    Mannequin

    Logged In: YES
    user_id=341410

    If your system has sufficient stack space (and/or a
    reasonably sane malloc), a recursion limit of 1000 should be
    fine. My windows systems print tracebacks properly for up
    to a recursion limit of around 5750 levels (after which I
    get MemoryErrors with tracebacks, not cores).

    Place a sys.setrecursionlimit() call in your site.py.

  12. rhettinger commented on May 23, 2005

    @rhettinger
    Contributor

    Logged In: YES
    user_id=80475

    FWIW, the OP's original situation may have tickled a
    genuine bug where one of the recursed into routines makes a
    malloc request but fails to check for, report, or gracefully
    exit from a memory error.

    His gdb trace may show the way, but I didn't see the bug.

  13. transferred this issue fromon Apr 9, 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

    interpreter-core

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions