aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorionagamed <ionagamed@yandex-team.com>2024-07-02 19:24:54 +0300
committerionagamed <ionagamed@yandex-team.com>2024-07-02 19:35:24 +0300
commitfe4668a34a034108c74b64e467489c0b50660c5f (patch)
tree58965d3787aace6e3fdfc6a5415e5d6587a60076 /library
parent1e0a4968300412641cea8500d75bbaa0e34c062f (diff)
downloadydb-fe4668a34a034108c74b64e467489c0b50660c5f.tar.gz
library: don't ignore map keys when checking json maxDepth
e5feb0553ad2842db9974979d9808105e6c5ba34
Diffstat (limited to 'library')
-rw-r--r--library/cpp/json/json_reader.cpp3
-rw-r--r--library/cpp/json/ut/json_reader_ut.cpp36
2 files changed, 35 insertions, 4 deletions
diff --git a/library/cpp/json/json_reader.cpp b/library/cpp/json/json_reader.cpp
index 9080e6dbca..0d048dfcd1 100644
--- a/library/cpp/json/json_reader.cpp
+++ b/library/cpp/json/json_reader.cpp
@@ -290,6 +290,9 @@ namespace NJson {
value.SetType(JSON_UNDEFINED);
}
S.emplace(&value);
+ if (!IsWithinStackBounds()) {
+ return false;
+ }
return true;
}
diff --git a/library/cpp/json/ut/json_reader_ut.cpp b/library/cpp/json/ut/json_reader_ut.cpp
index 115c85e1c7..07de6a7ac3 100644
--- a/library/cpp/json/ut/json_reader_ut.cpp
+++ b/library/cpp/json/ut/json_reader_ut.cpp
@@ -66,7 +66,7 @@ public:
}
};
-void GenerateDeepJson(TStringStream& stream, ui64 depth) {
+void GenerateDeepJsonArray(TStringStream& stream, ui64 depth) {
stream << "{\"key\":";
for (ui32 i = 0; i < depth - 1; ++i) {
stream << "[";
@@ -77,6 +77,16 @@ void GenerateDeepJson(TStringStream& stream, ui64 depth) {
stream << "}";
}
+void GenerateDeepJsonDict(TStringStream& stream, ui64 depth) {
+ for (ui64 i = 0; i < depth - 1; ++i) {
+ stream << "{\"key\":";
+ }
+ stream << "{}";
+ for (ui64 i = 0; i < depth - 1; ++i) {
+ stream << "}";
+ }
+}
+
Y_UNIT_TEST_SUITE(TJsonReaderTest) {
Y_UNIT_TEST(JsonReformatTest) {
TString data = "{\"null value\": null, \"intkey\": 10, \"double key\": 11.11, \"string key\": \"string\", \"array\": [1,2,3,\"TString\"], \"bool key\": true}";
@@ -414,7 +424,7 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
constexpr ui32 brackets = static_cast<ui32>(1e5);
TStringStream jsonStream;
- GenerateDeepJson(jsonStream, brackets);
+ GenerateDeepJsonArray(jsonStream, brackets);
TJsonReaderConfig config;
config.UseIterativeParser = true;
@@ -429,7 +439,25 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
{
TStringStream jsonStream;
- GenerateDeepJson(jsonStream, depth);
+ GenerateDeepJsonArray(jsonStream, depth);
+ TJsonReaderConfig config;
+ config.MaxDepth = depth;
+ TJsonValue v;
+ UNIT_ASSERT(ReadJsonTree(&jsonStream, &config, &v));
+ }
+
+ {
+ TStringStream jsonStream;
+ GenerateDeepJsonArray(jsonStream, depth);
+ TJsonReaderConfig config;
+ config.MaxDepth = depth - 1;
+ TJsonValue v;
+ UNIT_ASSERT(!ReadJsonTree(&jsonStream, &config, &v));
+ }
+
+ {
+ TStringStream jsonStream;
+ GenerateDeepJsonDict(jsonStream, depth);
TJsonReaderConfig config;
config.MaxDepth = depth;
TJsonValue v;
@@ -438,7 +466,7 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
{
TStringStream jsonStream;
- GenerateDeepJson(jsonStream, depth);
+ GenerateDeepJsonDict(jsonStream, depth);
TJsonReaderConfig config;
config.MaxDepth = depth - 1;
TJsonValue v;