diff options
-rw-r--r-- | sc/qa/filter/html/data/bad-json.html | 4 | ||||
-rw-r--r-- | sc/qa/filter/html/html.cxx | 15 | ||||
-rw-r--r-- | sc/source/filter/html/htmlpars.cxx | 10 |
3 files changed, 28 insertions, 1 deletions
diff --git a/sc/qa/filter/html/data/bad-json.html b/sc/qa/filter/html/data/bad-json.html new file mode 100644 index 000000000000..3a978e777f6d --- /dev/null +++ b/sc/qa/filter/html/data/bad-json.html @@ -0,0 +1,4 @@ +<meta http-equiv="content-type" content="text/html; charset=utf-8"><div><table> +<tbody> +<tr><td data-sheets-value="{"></td></tr> +</tbody></table></div> diff --git a/sc/qa/filter/html/html.cxx b/sc/qa/filter/html/html.cxx index 38b0500297ba..9e60af2565f9 100644 --- a/sc/qa/filter/html/html.cxx +++ b/sc/qa/filter/html/html.cxx @@ -85,6 +85,21 @@ CPPUNIT_TEST_FIXTURE(Test, testPasteTdAsText) CPPUNIT_ASSERT_EQUAL(CELLTYPE_STRING, eCellType); } +CPPUNIT_TEST_FIXTURE(Test, testPasteBadJson) +{ + createScDoc(); + + // Just care we don't crash on not-well-formed JSON: + ScDocument* pDoc = getScDoc(); + ScAddress aCellPos(/*nColP=*/0, /*nRowP=*/0, /*nTabP=*/0); + ScImportExport aImporter(*pDoc, aCellPos); + SvFileStream aFile(createFileURL(u"bad-json.html"), StreamMode::READ); + SvMemoryStream aMemory; + aMemory.WriteStream(aFile); + aMemory.Seek(0); + CPPUNIT_ASSERT(aImporter.ImportStream(aMemory, OUString(), SotClipboardFormatId::HTML)); +} + CPPUNIT_TEST_FIXTURE(Test, testPasteTdAsBools) { // Given an empty document: diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index fdbca6056c92..50b58bb9471e 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -84,7 +84,15 @@ void ParseDataSheetsValue(const OUString& rDataSheetsValue, std::optional<OUStri const char* pEncodedOption = aEncodedOption.getStr(); std::stringstream aStream(pEncodedOption); boost::property_tree::ptree aTree; - boost::property_tree::read_json(aStream, aTree); + try + { + boost::property_tree::read_json(aStream, aTree); + } + catch (const std::exception&) + { + SAL_WARN("sc", "ParseDataSheetsValue: not well-formed json"); + return; + } // The "1" key describes the original data type. auto it = aTree.find("1"); if (it != aTree.not_found()) |