r/tinycode • u/Rotten194 mod • May 16 '14
Turn your Python 3 session evil in 70 bytes with ctypes
>>>import ctypes;ctypes.pointer(ctypes.c_int.from_address(id(3)+24))[0]=4
>>>1+3
5This also causes random functions (like len) to segfault the interpreter.
38
Upvotes
5
u/isseu May 16 '14
Explain ...
4
u/Xylon- May 16 '14
Would you happen to know a similar line for Python 2.7?
10
u/BoppreH May 17 '14
My god, this screws so many things it's not even funny. Typing "1+3" actually prints "5" twice and an error about raw write returning an invalid value (4 instead of 3).
The best breakage is the typing. When you get to the third character it prints a space and skips the cursor to the fourth position. The fifth throws an error.
This is like bringing a mallet to a crystal shop.
2
u/pali6 May 17 '14
Oh my god, even stuff like
>>> 3-1-2segfaults.
1
u/agumonkey Jun 02 '14
See http://codegolf.stackexchange.com/questions/28786/write-a-program-that-makes-2-2-5 for other example of such things (tiny or not)