From 44d80c54581b818a7405e98a591ba3b0632747ee Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 9 Apr 2021 16:40:01 +0200 Subject: sw style copy: fix crash when handling a conditional paragraphy style - "Text body" is normally a conditional style for a full-blown, default SwDoc - SwTransferable::GetData() creates a temporary, stripped down SwDoc, which has a "Text body" style, but it's not conditional - SwDoc::CopyFormatArr() assumes that in case the target already has a style with a given name, then either both the source and destination styles are conditional, or neither - in practice this only causes a crash if the style is customized, as we skip default styles, probably that's why this was not noticed so far The Online case invokes this as part of lok::Document::getSelectionType(), so it was enough to set the paragraph style to Text body and then select some of that text (with a suitable document) to hit this. Based on a patch from Michael Meeks, thanks for that. (cherry picked from commit ce98bef935dccd79735615a9299b2aa7a1ab0b94) Conflicts: sw/qa/extras/tiledrendering/tiledrendering.cxx Change-Id: Ic3c27ec582ae1745469042856254313cbc996ee0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113970 Tested-by: Jenkins CollaboraOffice Reviewed-by: Mike Kaganski --- sw/source/core/doc/docfmt.cxx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx index f7a11676594e..e61d27c6a961 100644 --- a/sw/source/core/doc/docfmt.cxx +++ b/sw/source/core/doc/docfmt.cxx @@ -1328,9 +1328,18 @@ void SwDoc::CopyFormatArr( const SwFormatsBase& rSourceArr, //FEATURE::CONDCOLL if( RES_CONDTXTFMTCOLL == pSrc->Which() ) + { + if (pDstColl->Which() != RES_CONDTXTFMTCOLL) + { + // Target already had a style with a matching name, but it's not a conditional + // style, then don't copy the conditions. + continue; + } + // Copy the conditions, but delete the old ones first! static_cast(pDstColl)->SetConditions( static_cast(pSrc)->GetCondColls() ); + } //FEATURE::CONDCOLL } } -- cgit