Created
October 21, 2017 19:50
-
-
Save lovasoa/7e2267dd4a9f7c3b5b0c9235d0c4a8f5 to your computer and use it in GitHub Desktop.
Breaking python's json parser. Trying to find the smallest valid json object that python's default json module cannot parse.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import json | |
# Dichotomic search of the deepest parsable json array that python can parse | |
(m,M) = (0, int(1e6)) | |
while m+1<M: | |
middle = (m+M)//2 | |
try: | |
json.loads('[' * middle + ']' * middle) | |
m = middle | |
except RecursionError: | |
M = middle | |
print(M) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment