homepage

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.

classification
Title: sys.setrecursionlimit() crashes IDLE
Type: crash Stage: resolved
Components: None Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: amaury.forgeotdarc Nosy List: amaury.forgeotdarc, hanji, mark.dickinson, ned.deily, python-dev
Priority: normal Keywords: patch

Created on 2011年12月07日 08:49 by hanji, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue13546.patch amaury.forgeotdarc, 2011年12月07日 19:40 review
Messages (13)
msg148953 - (view) Author: Ji Han (hanji) Date: 2011年12月07日 08:49
The following code snippet will crash IDLE:
>>> import sys
>>> sys.setrecursionlimit((1<<31)-1)
The crash happens immediately and is consistently reproducible (environment: Windows 7 SP1 64-bit, Python 2.7.2 for Windows X86_64).
msg148956 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011年12月07日 09:57
Trying to set the recursion limit to a large number defeats its purpose. As documented in the Standard Library Reference:
The highest possible limit is platform-dependent. A user may need to set the limit higher when she has a program that requires deep recursion and a platform that supports a higher limit. This should be done with care, because a too-high limit can lead to a crash.
http://docs.python.org/library/sys.html#sys.setrecursionlimit 
msg148957 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011年12月07日 10:02
On the other hand, there is no reason for the recursion limit to be actually reached, just by setting it! Is there a hidden infinite recursion somewhere?
msg148958 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011年12月07日 10:05
hanji, could you start IDLE from a command prompt and try again:
 c:\python27\python.exe -m idlelib.idle
Do you see additional error messages?
msg148960 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011年12月07日 10:14
But after setting it, IDLE is going to be executing code. In the 64-bit Windows Python 2.7.2 that I have available, there were exceptions reported in the command line interpreter (not IDLE) after changing the recursion limit and then executing some code. Perhaps there is another of the known overflow error issues here. OTOH, similar reports have also been closed as "won't fix", most recently Issue12468. This doesn't seem worth the effort to investigate further. Feel free to reopen if you disagree.
msg148961 - (view) Author: Ji Han (hanji) Date: 2011年12月07日 11:28
@amaury.forgeotdarc
It says 'python.exe has stopped working'. Details:
 Problem Event Name:	APPCRASH
 Application Name:	python.exe
 Application Version:	0.0.0.0
 Application Timestamp:	4df4b010
 Fault Module Name:	MSVCR90.dll
 Fault Module Version:	9.0.30729.6161
 Fault Module Timestamp:	4dace4e7
 Exception Code:	c00000fd
 Exception Offset:	000000000001edcf
 ... ... ...
P.S. I'm well aware recursions won't go that deep. But crashing IDLE (instead of Raising an Error) by simply setting an option is still annoying.
msg148966 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011年12月07日 13:29
Tested on Linux:
Python 2.7.2+ (2.7:16c4137a413c+, Dec 4 2011, 22:56:38) 
[GCC 4.4.3] on linux2
>>> import sys
>>> sys.setrecursionlimit((1<<31)-1)
>>> import xx
Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in <type 'exceptions.ImportError'> ignored
Exception RuntimeError: 'maximum recursion depth exceeded in __subclasscheck__' in <type 'exceptions.ImportError'> ignored
Traceback (most recent call last):
This comes from PyErr_GivenExceptionMatches() which tries to "Temporarily bump the recursion limit", and calls Py_SetRecursionLimit(reclimit + 5); without any consideration for 32bit int overflow... and PyErr_WriteUnraisable() is called to display the error.
IDLE crashes (with a real stack overflow) because sys.stderr is a special RPCProxy object whose methods are found through a __getattr__. But __getattr__ is called when __getattribute__ raises AttributeError, right? To implement this, PyErr_GivenExceptionMatches() is called again, fails again, call PyErr_WriteUnraisable()... recursively.
The fix should be easy: do not bump the recursion limit when it's already too high.
msg148986 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011年12月07日 19:40
Here is a patch, with test.
msg148987 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011年12月07日 20:36
LGTM
msg148988 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2011年12月07日 20:51
New changeset 57de1ad15c54 by Amaury Forgeot d'Arc in branch '2.7':
Issue #13546: Fixed an overflow issue that could crash the intepreter when
http://hg.python.org/cpython/rev/57de1ad15c54 
msg148989 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011年12月07日 20:52
This will be fixed in the next 2.7 release, thanks for the report!
msg149030 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2011年12月08日 13:12
Style nit: how about
 'except ValueError as e'
instead of
 'except ValueError, e'
(Actually, why do we need e?)
msg149037 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2011年12月08日 14:28
'e' is "used" in the comment above: "isinstance(e, ValueError) used to fail"...
I agree to use the modern 'as' syntax.
History
Date User Action Args
2022年04月11日 14:57:24adminsetgithub: 57755
2011年12月08日 14:28:41amaury.forgeotdarcsetmessages: + msg149037
2011年12月08日 13:12:28mark.dickinsonsetnosy: + mark.dickinson
messages: + msg149030
2011年12月07日 20:52:52amaury.forgeotdarcsetstatus: open -> closed
resolution: fixed
messages: + msg148989

stage: patch review -> resolved
2011年12月07日 20:51:15python-devsetnosy: + python-dev
messages: + msg148988
2011年12月07日 20:36:52ned.deilysetmessages: + msg148987
2011年12月07日 19:40:39amaury.forgeotdarcsetassignee: amaury.forgeotdarc
stage: needs patch -> patch review
2011年12月07日 19:40:19amaury.forgeotdarcsetfiles: + issue13546.patch
keywords: + patch
messages: + msg148986
2011年12月07日 13:29:57amaury.forgeotdarcsetstatus: closed -> open
resolution: wont fix -> (no value)
messages: + msg148966

stage: resolved -> needs patch
2011年12月07日 11:28:22hanjisetmessages: + msg148961
2011年12月07日 10:14:40ned.deilysetmessages: + msg148960
2011年12月07日 10:05:29amaury.forgeotdarcsetmessages: + msg148958
2011年12月07日 10:02:06amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg148957
2011年12月07日 09:57:53ned.deilysetstatus: open -> closed

type: crash

nosy: + ned.deily
messages: + msg148956
resolution: wont fix
stage: resolved
2011年12月07日 08:49:03hanjicreate

AltStyle によって変換されたページ (->オリジナル) /