[Python-Dev] another dict crasher

Michael Hudson mwh@python.net
01 Jun 2001 12:54:40 +0100


Adapted from a report on comp.lang.python from Wolfgang Lipp:

class Child:
    def __init__(self, parent):
        self.__dict__['parent'] = parent
    def __getattr__(self, attr):
        self.parent.a = 1
        self.parent.b = 1
        self.parent.c = 1
        self.parent.d = 1
        self.parent.e = 1
        self.parent.f = 1
        self.parent.g = 1
        self.parent.h = 1
        self.parent.i = 1
        return getattr(self.parent, attr)

class Parent:
    def __init__(self):
        self.a = Child(self)

print Parent().__dict__ 

segfaults both 2.1 and current (well, maybe a day old) CVS.  Haven't
tried Tim's latest patch, but I don't believe that will make any
difference.

It's obvious <wink> what's happening; the dict's resizing inside the
for loop in dict_repr and the ep pointer is dangling.

By the time we've shaken all of these out of dictobject.c it's going
to be pretty close to free-threading safe, I'd have thought.

reentrancy-sucks-ly y'rs
M.

-- 
  But since I'm not trying to impress  anybody in The Software Big
  Top, I'd rather walk the wire using a big pole, a safety harness,
  a net, and with the wire not more than 3 feet off the ground.
                                   -- Grant Griffin, comp.lang.python