Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/lib_json/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
// Define JSONCPP_DEPRECATED_STACK_LIMIT as an appropriate integer at compile
// time to change the stack limit
#if !defined(JSONCPP_DEPRECATED_STACK_LIMIT)
#define JSONCPP_DEPRECATED_STACK_LIMIT 1000
#define JSONCPP_DEPRECATED_STACK_LIMIT 256
#endif

static size_t const stackLimit_g =
Expand Down Expand Up @@ -1932,7 +1932,7 @@ void CharReaderBuilder::strictMode(Json::Value* settings) {
(*settings)["allowDroppedNullPlaceholders"] = false;
(*settings)["allowNumericKeys"] = false;
(*settings)["allowSingleQuotes"] = false;
(*settings)["stackLimit"] = 1000;
(*settings)["stackLimit"] = 256;
(*settings)["failIfExtra"] = true;
(*settings)["rejectDupKeys"] = true;
(*settings)["allowSpecialFloats"] = false;
Expand All @@ -1949,7 +1949,7 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
(*settings)["allowDroppedNullPlaceholders"] = false;
(*settings)["allowNumericKeys"] = false;
(*settings)["allowSingleQuotes"] = false;
(*settings)["stackLimit"] = 1000;
(*settings)["stackLimit"] = 256;
(*settings)["failIfExtra"] = false;
(*settings)["rejectDupKeys"] = false;
(*settings)["allowSpecialFloats"] = false;
Expand All @@ -1965,7 +1965,7 @@ void CharReaderBuilder::ecma404Mode(Json::Value* settings) {
(*settings)["allowDroppedNullPlaceholders"] = false;
(*settings)["allowNumericKeys"] = false;
(*settings)["allowSingleQuotes"] = false;
(*settings)["stackLimit"] = 1000;
(*settings)["stackLimit"] = 256;
(*settings)["failIfExtra"] = true;
(*settings)["rejectDupKeys"] = false;
(*settings)["allowSpecialFloats"] = false;
Expand Down
10 changes: 10 additions & 0 deletions src/test_lib_json/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3355,6 +3355,16 @@ JSONTEST_FIXTURE_LOCAL(CharReaderTest, parseWithStackLimit) {
JSONTEST_ASSERT_THROWS(
reader->parse(doc, doc + std::strlen(doc), &root, &errs));
}
// Default stack limit should reject deeply nested input (regression test for
// stack exhaustion from fuzz input like [[[[...]]]])
{
Json::CharReaderBuilder defaultBuilder;
Json::String nested(300, '[');
CharReaderPtr reader(defaultBuilder.newCharReader());
Json::String errs;
JSONTEST_ASSERT_THROWS(reader->parse(
nested.data(), nested.data() + nested.size(), &root, &errs));
}

#endif // JSON_USE_EXCEPTION
}
Expand Down
Loading