Skip to content

Commit

Permalink
Issue 3514: Fixed segfault dues to infinite loop in __getattr__.
Browse files Browse the repository at this point in the history
  • Loading branch information
avassalotti committed Aug 15, 2008
1 parent e1e48ea commit 1f9d907
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Lib/test/pickletester.py
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,14 @@ def test_reduce_calls_base(self):
y = self.loads(s)
self.assertEqual(y._reduce_called, 1)

def test_bad_getattr(self):
x = BadGetattr()
for proto in 0, 1:
self.assertRaises(RuntimeError, self.dumps, x, proto)
# protocol 2 don't raise a RuntimeError.
d = self.dumps(x, 2)
self.assertRaises(RuntimeError, self.loads, d)

# Test classes for reduce_ex

class REX_one(object):
Expand Down Expand Up @@ -949,6 +957,10 @@ def __init__(self, a, b, c):
# raise an error, to make sure this isn't called
raise TypeError("SimpleNewObj.__init__() didn't expect to get called")

class BadGetattr:
def __getattr__(self, key):
self.foo

class AbstractPickleModuleTests(unittest.TestCase):

def test_dump_closed_file(self):
Expand Down
7 changes: 5 additions & 2 deletions Modules/_pickle.c
Original file line number Diff line number Diff line change
Expand Up @@ -3834,8 +3834,11 @@ load_build(UnpicklerObject *self)
inst = self->stack->data[self->stack->length - 1];

setstate = PyObject_GetAttrString(inst, "__setstate__");
if (setstate == NULL && PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
if (setstate == NULL) {
if (PyErr_ExceptionMatches(PyExc_AttributeError))
PyErr_Clear();
else
return -1;
}
else {
PyObject *result;
Expand Down

0 comments on commit 1f9d907

Please sign in to comment.