This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ldeller
Recipients ldeller
Date 2009-02-12.04:28:32
SpamBayes Score 3.3825875e-06
Marked as misclassified No
Message-id <1234412915.77.0.527314714811.issue5223@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2009-02-12 04:28:36ldellersetrecipients: + ldeller
2009-02-12 04:28:35ldellersetmessageid: <1234412915.77.0.527314714811.issue5223@psf.upfronthosting.co.za>
2009-02-12 04:28:34ldellerlinkissue5223 messages
2009-02-12 04:28:33ldellercreate