Skip to content

Commit 4f7e758

Browse files
committed
Validate depth in valid_json?
1 parent 10a3ecd commit 4f7e758

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

ext/rapidjson/parser.hh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@
77
using namespace rapidjson;
88

99
class NullHandler : public BaseReaderHandler<UTF8<>, NullHandler> {
10+
static const int MAX_DEPTH = 256;
11+
int depth = 0;
12+
bool push() {
13+
return depth++ < MAX_DEPTH;
14+
}
15+
bool pop() {
16+
return depth-- > 0;
17+
}
18+
public:
19+
bool StartObject() { return push(); }
20+
bool EndObject(SizeType s) { return pop(); }
21+
bool StartArray() { return push(); }
22+
bool EndArray(SizeType s) { return pop(); }
1023
};
1124

1225
struct RubyObjectHandler : public BaseReaderHandler<UTF8<>, RubyObjectHandler> {

0 commit comments

Comments
 (0)