How can I cause Python 3.5 to crash?
There are plenty of ways through ctypes
. For example, a corrected version of your code:
p = ctypes.pointer(ctypes.c_char.from_address(5))
p[0] = b'x'
If you don't want to use ctypes, you could trigger a C stack overflow in the dict.__repr__
implementation:
x = {}
for i in range(1000000):
x = {1: x}
repr(x)
This might get patched in a future Python release, but for now, it should produce a hard crash.
There are also ways to do it by constructing your own bytecode objects, since Python does almost nothing to make sure that the bytecode it's executing makes sense.
Found this one-liner:
exec(type((lambda:0).__code__)(0,1,0,0,0,b'',(),(),(),'','',1,b''))
which was snagged from this code-golf question:
- Crash (i.e. cause the interpreter to stop working and force close) Python
Here is a simple way to crash python:
def crash():
try:
crash()
except:
crash()
crash()
Simply put 0 / 0 on the line of code you want to trigger the crash. You will get a ZeroDivisionError
I think this is the easiest way to force a crash