[Python-bugs-list] [ python-Bugs-793822 ] gc.get_referrers() is
inherently dangerous
SourceForge.net
noreply at sourceforge.net
Sat Aug 23 11:17:54 EDT 2003
Bugs item #793822, was opened at 2003-08-23 17:17
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=793822&group_id=5470
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Armin Rigo (arigo)
Assigned to: Nobody/Anonymous (nobody)
Summary: gc.get_referrers() is inherently dangerous
Initial Comment:
gc.get_referrers() can be used to crash any Python
interpreter because it allows the user to obtain
objects which are still under construction.
Here is an example where an iterator can use it to
obtain a tuple while it is still being populated by the
'tuple' built-in function. The following example
triggers a SystemError, but as the tuple 't' is at the
moment still full of null values it can easily generate
segfaults instead.
from gc import get_referrers
def iter():
tag = object()
yield tag # 'tag' gets stored in the result tuple
lst = [x for x in get_referrers(tag)
if isinstance(x, tuple)]
t = lst[0] # this *is* the result tuple
print t # full of nulls !
tuple(iter())
Unless someone has more ideas than me as to how to
prevent this problem, I'd suggest that
gc.get_referrers() should be deemed 'officially
dangerous' in the docs.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=793822&group_id=5470
More information about the Python-bugs-list
mailing list