Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4b5a76

Browse files
committed
collected my segfaulting Python examples from the SF trackers
(is the purpose of the crashers directory to scare people? :-)
1 parent f60cd47 commit b4b5a76

8 files changed

Lines changed: 99 additions & 0 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# http://python.org/sf/1174712
3+
4+
import types
5+
6+
class X(types.ModuleType, str):
7+
"""Such a subclassing is incorrectly allowed --
8+
see the SF bug report for explanations"""
9+
10+
if __name__ == '__main__':
11+
X('name') # segfault: ModuleType.__init__() reads
12+
# the dict at the wrong offset
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# http://python.org/sf/1202533
3+
4+
import new, operator
5+
6+
class A:
7+
pass
8+
A.__mul__ = new.instancemethod(operator.mul, None, A)
9+
10+
if __name__ == '__main__':
11+
A()*2 # segfault: infinite recursion in C
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# http://python.org/sf/1202533
3+
4+
class A(str):
5+
__get__ = getattr
6+
7+
if __name__ == '__main__':
8+
a = A('a')
9+
A.a = a
10+
a.a # segfault: infinite recursion in C
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
# http://python.org/sf/1202533
3+
4+
class A(object):
5+
pass
6+
A.__call__ = A()
7+
8+
if __name__ == '__main__':
9+
A()() # segfault: infinite recursion in C
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
# http://python.org/sf/1202533
3+
4+
if __name__ == '__main__':
5+
lst = [apply]
6+
lst.append(lst)
7+
apply(*lst) # segfault: infinite recursion in C
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# http://python.org/sf/1267884
3+
4+
import types
5+
6+
class C:
7+
__str__ = types.InstanceType.__str__
8+
9+
if __name__ == '__main__':
10+
str(C()) # segfault: infinite recursion in C
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
# http://python.org/sf/1303614
3+
4+
class Strange(object):
5+
def __hash__(self):
6+
return hash('hello')
7+
8+
def __eq__(self, other):
9+
x.__dict__ = {} # the old x.__dict__ is deallocated
10+
return False
11+
12+
13+
class X(object):
14+
pass
15+
16+
if __name__ == '__main__':
17+
v = 123
18+
x = X()
19+
x.__dict__ = {Strange(): 42,
20+
'hello': v+456}
21+
x.hello # segfault: the above dict is accessed after it's deallocated
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# http://python.org/sf/1303614
3+
4+
class Y(object):
5+
pass
6+
7+
class type_with_modifiable_dict(Y, type):
8+
pass
9+
10+
class MyClass(object):
11+
"""This class has its __dict__ attribute completely exposed:
12+
user code can read, reassign and even delete it.
13+
"""
14+
__metaclass__ = type_with_modifiable_dict
15+
16+
17+
if __name__ == '__main__':
18+
del MyClass.__dict__ # if we set tp_dict to NULL,
19+
print MyClass # doing anything with MyClass segfaults

0 commit comments

Comments
 (0)