Skip to content

Instantly share code, notes, and snippets.

@lovasoa
Created October 21, 2017 19:50
Show Gist options
  • Save lovasoa/7e2267dd4a9f7c3b5b0c9235d0c4a8f5 to your computer and use it in GitHub Desktop.
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.
#!/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