diff --git a/interfaces/innerkits/formatter/dfx_json_formatter.cpp b/interfaces/innerkits/formatter/dfx_json_formatter.cpp index ac349891bac541a3055b61ea8456da37a51cb195..677c5ce8c3a8a3c68e4ce32d055ccb8944cd8b0d 100644 --- a/interfaces/innerkits/formatter/dfx_json_formatter.cpp +++ b/interfaces/innerkits/formatter/dfx_json_formatter.cpp @@ -85,7 +85,11 @@ bool DfxJsonFormatter::FormatJsonStack(const std::string& jsonStack, std::string outStackStr.append("Failed to parse json stack info."); return false; } - + constexpr int maxThreadCount = 10000; + if (threads.size() > maxThreadCount) { + outStackStr.append("Thread count exceeds limit(10000)."); + return false; + } for (uint32_t i = 0; i < threads.size(); ++i) { std::string ss; Json::Value thread = threads[i]; @@ -93,7 +97,14 @@ bool DfxJsonFormatter::FormatJsonStack(const std::string& jsonStack, std::string thread["thread_name"].isConvertibleTo(Json::stringValue)) { ss += "Tid:" + thread["tid"].asString() + ", Name:" + thread["thread_name"].asString() + "\n"; } + if (!thread.isMember("frames") || !thread["frames"].isArray()) { + continue; + } const Json::Value frames = thread["frames"]; + constexpr int maxFrameNum = 1000; + if (frames.size() > maxFrameNum) { + continue; + } for (uint32_t j = 0; j < frames.size(); ++j) { std::string frameStr = ""; bool formatStatus = false; @@ -110,6 +121,7 @@ bool DfxJsonFormatter::FormatJsonStack(const std::string& jsonStack, std::string return false; } } + outStackStr.append(ss); } return true;