This repository was archived by the owner on Jun 17, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +17
-0
lines changed Expand file tree Collapse file tree 5 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,7 @@ TEST_FILES = \
9595 $(TEST_DATA_DIR ) /fail41.json \
9696 $(TEST_DATA_DIR ) /fail42.json \
9797 $(TEST_DATA_DIR ) /fail44.json \
98+ $(TEST_DATA_DIR ) /fail45.json \
9899 $(TEST_DATA_DIR ) /fail3.json \
99100 $(TEST_DATA_DIR ) /fail4.json \
100101 $(TEST_DATA_DIR ) /fail5.json \
@@ -105,6 +106,7 @@ TEST_FILES = \
105106 $(TEST_DATA_DIR ) /pass1.json \
106107 $(TEST_DATA_DIR ) /pass2.json \
107108 $(TEST_DATA_DIR ) /pass3.json \
109+ $(TEST_DATA_DIR ) /pass4.json \
108110 $(TEST_DATA_DIR ) /round1.json \
109111 $(TEST_DATA_DIR ) /round2.json \
110112 $(TEST_DATA_DIR ) /round3.json \
Original file line number Diff line number Diff line change 88#include " univalue.h"
99#include " univalue_utffilter.h"
1010
11+ /*
12+ * According to stackexchange, the original json test suite wanted
13+ * to limit depth to 22. Widely-deployed PHP bails at depth 512,
14+ * so we will follow PHP's lead, which should be more than sufficient
15+ * (further stackexchange comments indicate depth > 32 rarely occurs).
16+ */
17+ static const size_t MAX_JSON_DEPTH = 512 ;
18+
1119static bool json_isdigit (int ch)
1220{
1321 return ((ch >= ' 0' ) && (ch <= ' 9' ));
@@ -323,6 +331,9 @@ bool UniValue::read(const char *raw, size_t size)
323331 stack.push_back (newTop);
324332 }
325333
334+ if (stack.size () > MAX_JSON_DEPTH)
335+ goto return_fail;
336+
326337 if (utyp == VOBJ)
327338 setExpect (OBJ_NAME);
328339 else
Original file line number Diff line number Diff line change 1+ [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[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[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]
Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ static const char *filenames[] = {
114114 " fail41.json" , // invalid unicode: unfinished UTF-8
115115 " fail42.json" , // valid json with garbage following a nul byte
116116 " fail44.json" , // unterminated string
117+ " fail45.json" , // nested beyond max depth
117118 " fail3.json" ,
118119 " fail4.json" , // extra comma
119120 " fail5.json" ,
@@ -124,6 +125,7 @@ static const char *filenames[] = {
124125 " pass1.json" ,
125126 " pass2.json" ,
126127 " pass3.json" ,
128+ " pass4.json" ,
127129 " round1.json" , // round-trip test
128130 " round2.json" , // unicode
129131 " round3.json" , // bare string
You can’t perform that action at this time.
0 commit comments