Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch:
Changeset: r97705:38ede7e5cb5a
Date: 2019-10-01 22:59 +0200
http://bitbucket.org/pypy/pypy/changeset/38ede7e5cb5a/
Log: corner case in the json decoder: like regular object maps, don't
make the json maps arbitrarily huge
diff --git a/pypy/module/_pypyjson/interp_decoder.py
b/pypy/module/_pypyjson/interp_decoder.py
--- a/pypy/module/_pypyjson/interp_decoder.py
+++ b/pypy/module/_pypyjson/interp_decoder.py
@@ -69,6 +69,9 @@
# hit in the cache
STRING_CACHE_USEFULNESS_FACTOR = 4
+ # don't make arbitrarily huge maps
+ MAX_MAP_SIZE = 100
+
def __init__(self, space, s):
self.space = space
@@ -368,7 +371,7 @@
return w_res
elif ch == ',':
i = self.skip_whitespace(i)
- if currmap.is_state_blocked():
+ if currmap.is_state_blocked() or nextindex > self.MAX_MAP_SIZE:
self.scratch.append(values_w) # can reuse next time
dict_w = self._switch_to_dict(currmap, values_w, nextindex)
return self.decode_object_dict(i, start, dict_w)
diff --git a/pypy/module/_pypyjson/test/test__pypyjson.py
b/pypy/module/_pypyjson/test/test__pypyjson.py
--- a/pypy/module/_pypyjson/test/test__pypyjson.py
+++ b/pypy/module/_pypyjson/test/test__pypyjson.py
@@ -469,6 +469,14 @@
res = _pypyjson.loads(json)
assert res == [{u'a': 1}, {u'a': 2}]
+ def test_huge_map(self):
+ import _pypyjson
+ import __pypy__
+ s = '{' + ",".join('"%s": %s' % (i, i) for i in range(200)) + '}'
+ res = _pypyjson.loads(s)
+ assert len(res) == 200
+ assert __pypy__.strategy(res) == "UnicodeDictStrategy"
+
def test_tab_in_string_should_fail(self):
import _pypyjson
# http://json.org/JSON_checker/test/fail25.json
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit