sw/qa/extras/rtfexport/data/invalidParagraphStyle.rtf | 14 ++++++++++++++ sw/qa/extras/rtfexport/rtfexport3.cxx | 9 +++++++++ writerfilter/source/dmapper/DomainMapper_Impl.cxx | 10 +++++++++- 3 files changed, 32 insertions(+), 1 deletion(-)
New commits: commit 466cc615de49a646c82af14657a05e240e4a640c Author: Vasily Melenchuk <vasily.melenc...@cib.de> AuthorDate: Wed Dec 28 23:52:10 2022 +0300 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Mon Jan 9 23:44:41 2023 +0000 ms format import: better handling for invalid styles If referred paragraph style is not found or it is not a paragraph style, this can lead to exceptions in writer core and thus current paragraph can be not corretly initialized. For example, numbering can be not applied because of exception of not found style earlier. This is not a critical error, we should just not apply a style we could not resolve. Of course such documents are invalid but bit more tolerance to errors will not harm. Change-Id: I9150786e6357a7d6098440bac29ec501fc6aa802 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144852 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145194 diff --git a/sw/qa/extras/rtfexport/data/invalidParagraphStyle.rtf b/sw/qa/extras/rtfexport/data/invalidParagraphStyle.rtf new file mode 100644 index 000000000000..cb5ec80eb3cf --- /dev/null +++ b/sw/qa/extras/rtfexport/data/invalidParagraphStyle.rtf @@ -0,0 +1,14 @@ +{\rtf1 + +{\stylesheet +{\cs30\fs72 Super Duper Style;}} + +{\*\listtable +{\list +{\listlevel\levelstartat1{\leveltext\'02\'00.;}{\levelnumbers\'01;}} +{\listname ;}\listid1235362366}} +{\*\listoverridetable{\listoverride\listid1235362366\listoverridecount0\ls1}} + +\pard\s30\ls1\fs24 AAA BBB CCC\par + +} diff --git a/sw/qa/extras/rtfexport/rtfexport3.cxx b/sw/qa/extras/rtfexport/rtfexport3.cxx index 90adb69f2bf7..6c1a4d524b7f 100644 --- a/sw/qa/extras/rtfexport/rtfexport3.cxx +++ b/sw/qa/extras/rtfexport/rtfexport3.cxx @@ -514,6 +514,15 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf127806) CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(635), aSize.Width); } +DECLARE_RTFEXPORT_TEST(testInvalidParagraphStyle, "invalidParagraphStyle.rtf") +{ + // Given test has character style #30, but referred as paragraph style #30 + // This was causing exception in finishParagraph(), so numbering and other + // properties were not applied. Ensure numbering is still here + sal_Int16 numFormat = getNumberingTypeOfParagraph(1); + CPPUNIT_ASSERT_EQUAL(style::NumberingType::ARABIC, numFormat); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx index f0fbd05209c5..bcfcbc7c72dd 100644 --- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx +++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx @@ -1934,13 +1934,21 @@ void DomainMapper_Impl::finishParagraph( const PropertyMapPtr& pPropertyMap, con #endif const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByConvertedStyleName( GetCurrentParaStyleName() ); - OSL_ENSURE( pEntry, "no style sheet found" ); + SAL_WARN_IF(!pEntry, "writerfilter.dmapper", "no style sheet found"); const StyleSheetPropertyMap* pStyleSheetProperties = pEntry ? pEntry->pProperties.get() : nullptr; sal_Int32 nListId = pParaContext ? pParaContext->props().GetListId() : -1; bool isNumberingViaStyle(false); bool isNumberingViaRule = nListId > -1; if ( !bRemove && pStyleSheetProperties && pParaContext ) { + if (!pEntry || pEntry->nStyleTypeCode != StyleType::STYLE_TYPE_PARA) { + // We could not resolve paragraph style or it is not a paragraph style + // Remove this style reference, otherwise it will cause exceptions during further + // processing and not all paragraph styles will be initialized. + SAL_WARN("writerfilter.dmapper", "Paragraph style is incorrect. Ignored"); + pParaContext->Erase(PROP_PARA_STYLE_NAME); + } + bool bNumberingFromBaseStyle = false; if (!isNumberingViaRule) nListId = lcl_getListId(pEntry, GetStyleSheetTable(), bNumberingFromBaseStyle);