diff options
author | Matt Cotter <matt.cotter@mongodb.com> | 2016-11-28 15:21:49 -0500 |
---|---|---|
committer | Matt Cotter <matt.cotter@mongodb.com> | 2016-11-29 17:09:05 -0500 |
commit | 2b8fe6c13cb08c8de2e1cd622ca8456d0f08caab (patch) | |
tree | 5cd4254ef44bf6b6fe13ec57df4a09caabc2d88c /jstests | |
parent | 84650bdac943af4d30d1b26a1a176038828a9993 (diff) | |
download | mongo-2b8fe6c13cb08c8de2e1cd622ca8456d0f08caab.tar.gz |
SERVER-8308 limit tojson call depth
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/noPassthrough/nested_tojson.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/jstests/noPassthrough/nested_tojson.js b/jstests/noPassthrough/nested_tojson.js new file mode 100644 index 00000000000..f45d40a2b93 --- /dev/null +++ b/jstests/noPassthrough/nested_tojson.js @@ -0,0 +1,31 @@ +(function() { + "use strict"; + + const tooMuchRecursion = (1 << 16); + + const nestobj = (depth) => { + let doc = {}; + let cur = doc; + for (let i = 0; i < depth; i++) { + cur[i] = {}; + cur = cur[i]; + } + cur['a'] = 'foo'; + return doc + }; + + const nestarr = (depth) => { + let doc = [0]; + let cur = doc; + for (let i = 0; i < depth; i++) { + cur[0] = [0]; + cur = cur[0]; + } + cur[0] = 'foo'; + return doc; + }; + + assert.doesNotThrow( + tojson, [nestobj(tooMuchRecursion)], 'failed to print deeply nested object'); + assert.doesNotThrow(tojson, [nestarr(tooMuchRecursion)], 'failed to print deeply nested array'); +})(); |