Message17902
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.
|
|
Date |
User |
Action |
Args |
2007-08-23 14:16:20 | admin | link | issue793822 messages |
2007-08-23 14:16:20 | admin | create | |
|