Skip to content

Commit 4dca80d

Browse files
committed
limit stackDepth
1 parent 249ad9f commit 4dca80d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/lib_json/json_reader.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,9 @@ class OurReader {
10341034
Location lastValueEnd_;
10351035
Value* lastValue_;
10361036
std::string commentsBefore_;
1037-
OurFeatures features_;
1037+
int stackDepth_;
1038+
1039+
OurFeatures const features_;
10381040
bool collectComments_;
10391041
}; // OurReader
10401042

@@ -1065,6 +1067,7 @@ bool OurReader::parse(const char* beginDoc,
10651067
nodes_.pop();
10661068
nodes_.push(&root);
10671069

1070+
stackDepth_ = 0;
10681071
bool successful = readValue();
10691072
Token token;
10701073
skipCommentTokens(token);
@@ -1087,6 +1090,8 @@ bool OurReader::parse(const char* beginDoc,
10871090
}
10881091

10891092
bool OurReader::readValue() {
1093+
if (stackDepth_ >= features_.stackLimit_) throw std::runtime_error("Exceeded stackLimit in readValue().");
1094+
++stackDepth_;
10901095
Token token;
10911096
skipCommentTokens(token);
10921097
bool successful = true;
@@ -1158,6 +1163,7 @@ bool OurReader::readValue() {
11581163
lastValue_ = &currentValue();
11591164
}
11601165

1166+
--stackDepth_;
11611167
return successful;
11621168
}
11631169

0 commit comments

Comments
 (0)