[issue5223] infinite recursion in PyErr_WriteUnraisable

lplatypus report at bugs.python.org
Thu Feb 12 05:28:35 CET 2009


New submission from lplatypus <luke at deller.id.au>:

Here is an example of pure Python code which can cause the interpreter
to crash.

I can reproduce the problem in 2.6.0 and 2.6.1 but not in 2.5.2.

The __getattr__ function in this example is interesting in that it
involves infinite recursion, but then the RuntimeError("maximum
recursion depth exceeded") actually causes it to behave correctly.  This
is due to the behaviour of hasattr which suppresses any exception caught
when checking for attributes.

Added to the mix we have sys.stderr replaced by an instance with a write
method.  The key ingredient here is that getattr(sys.stderr, "write")
invokes Python code.  Near the interpreter's recursion limit this python
code can fail.  This causes infinite recursion in C.

Here is a snippet of the call stack from gdb showing the recursion cycle
(using 2.6.0 source code):

#9  0x00000000004a442c in PyErr_WriteUnraisable (obj=0x64ae40)
    at Python/errors.c:606
#10 0x00000000004a48f5 in PyErr_GivenExceptionMatches (err=0x64ae40,
    exc=0x64ae40) at Python/errors.c:115
#11 0x0000000000466056 in slot_tp_getattr_hook (self=0x70a910,
    name=0x2b4a94d47e70) at Objects/typeobject.c:5426
#12 0x0000000000449f4d in PyObject_GetAttrString (v=0x70a910,
    name=0x7fff155e2fe0 <Address 0x7fff155e2fe0 out of bounds>)
    at Objects/object.c:1176
#13 0x000000000042e316 in PyFile_WriteObject (v=0xd02d88, f=0x70a910,
flags=1)
    at Objects/fileobject.c:2362
#14 0x000000000042e5c5 in PyFile_WriteString (s=0x51704a "Exception ",
    f=0x70a910) at Objects/fileobject.c:2422
#15 0x00000000004a442c in PyErr_WriteUnraisable (obj=0x64ae40)
    at Python/errors.c:606

----------
components: Interpreter Core
files: recursebug.py
messages: 81721
nosy: ldeller
severity: normal
status: open
title: infinite recursion in PyErr_WriteUnraisable
type: crash
versions: Python 2.6
Added file: http://bugs.python.org/file13044/recursebug.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5223>
_______________________________________


More information about the Python-bugs-list mailing list