tdf#161858 prevent crashing by catching any JSON exceptions

Change-Id: I733ac428c96a96be668d6334db8c71efaf51beff
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170818
Reviewed-by: Patrick Luby <guibomacdev@gmail.com>
Tested-by: Jenkins
This commit is contained in:
Patrick Luby 2024-07-21 14:22:57 -04:00 committed by Patrick Luby
parent b5c24d544f
commit d81ffa179d

View file

@ -217,7 +217,16 @@ uno::Sequence<SingleProofreadingError> parseJson(std::string&& json, std::string
{ {
std::stringstream aStream(std::move(json)); // Optimized in C++20 std::stringstream aStream(std::move(json)); // Optimized in C++20
boost::property_tree::ptree aRoot; boost::property_tree::ptree aRoot;
boost::property_tree::read_json(aStream, aRoot);
// tdf#161858 prevent crashing by catching any JSON exceptions
try
{
boost::property_tree::read_json(aStream, aRoot);
}
catch (std::runtime_error&)
{
SAL_WARN("languagetool", "parseJson: read_json() threw exception");
}
if (auto tree = aRoot.get_child_optional(path)) if (auto tree = aRoot.get_child_optional(path))
{ {