From d81ffa179df1d1279e98ff4aa5c58e1ea4720db1 Mon Sep 17 00:00:00 2001 From: Patrick Luby Date: Sun, 21 Jul 2024 14:22:57 -0400 Subject: [PATCH] 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 Tested-by: Jenkins --- .../spellcheck/languagetool/languagetoolimp.cxx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx index e565b3f269fe..08da873e64b7 100644 --- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx +++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx @@ -217,7 +217,16 @@ uno::Sequence parseJson(std::string&& json, std::string { std::stringstream aStream(std::move(json)); // Optimized in C++20 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)) {