sw/CppunitTest_sw_core_attr.mk     |   75 +++++++++++++++++++++++++++++++++++++
 sw/Module_sw.mk                    |    1 
 sw/qa/core/attr/attr.cxx           |   53 ++++++++++++++++++++++++++
 sw/qa/core/attr/data/attr-set.docx |binary
 sw/source/core/attr/swatrset.cxx   |    3 -
 5 files changed, 131 insertions(+), 1 deletion(-)

New commits:
commit 7fdedf8a93caf292bdb643bfc9861ebc624b1929
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Mar 30 11:20:12 2022 +0200
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Wed Mar 30 20:46:32 2022 +0200

    sw: fix crash in SwAttrSet::CopyToModify()
    
    Regression from commit 938a4d6624a78f3e272b3c4c07f314cb0c6db723
    (tdf#128375 sw: fix copying RES_PARATR_LIST_AUTOFMT to different SwDoc,
    2019-11-01), the problem is that we may get an autofmt pool item which
    is set, but its style handle is empty. Assume that this is the same case
    as having no autofmt at all.
    
    (cherry picked from commit ddfafd9b67e6e61c144b29ac73bbafb413ddf03b)
    
    Conflicts:
            sw/Module_sw.mk
            sw/source/core/attr/swatrset.cxx
    
    Change-Id: I87494fd04687d31201b4ec712cb0fb1ec7362b46
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132312
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/sw/CppunitTest_sw_core_attr.mk b/sw/CppunitTest_sw_core_attr.mk
new file mode 100644
index 000000000000..7ca0060290e3
--- /dev/null
+++ b/sw/CppunitTest_sw_core_attr.mk
@@ -0,0 +1,75 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#*************************************************************************
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+#*************************************************************************
+
+$(eval $(call gb_CppunitTest_CppunitTest,sw_core_attr))
+
+$(eval $(call gb_CppunitTest_use_common_precompiled_header,sw_core_attr))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sw_core_attr, \
+    sw/qa/core/attr/attr \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sw_core_attr, \
+    comphelper \
+    cppu \
+    cppuhelper \
+    editeng \
+    sal \
+    sfx \
+    svl \
+    svx \
+    svxcore \
+    sw \
+       swqahelper \
+    test \
+    unotest \
+    utl \
+    vcl \
+    tl \
+))
+
+$(eval $(call gb_CppunitTest_use_externals,sw_core_attr,\
+    boost_headers \
+    libxml2 \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sw_core_attr,\
+    -I$(SRCDIR)/sw/inc \
+    -I$(SRCDIR)/sw/source/core/inc \
+    -I$(SRCDIR)/sw/source/uibase/inc \
+    -I$(SRCDIR)/sw/qa/inc \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sw_core_attr,\
+       udkapi \
+       offapi \
+       oovbaapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sw_core_attr))
+$(eval $(call gb_CppunitTest_use_vcl,sw_core_attr))
+
+$(eval $(call gb_CppunitTest_use_rdb,sw_core_attr,services))
+
+$(eval $(call gb_CppunitTest_use_custom_headers,sw_core_attr,\
+    officecfg/registry \
+))
+
+$(eval $(call gb_CppunitTest_use_configuration,sw_core_attr))
+
+$(eval $(call gb_CppunitTest_use_uiconfigs,sw_core_attr, \
+    modules/swriter \
+))
+
+$(eval $(call gb_CppunitTest_use_more_fonts,sw_core_attr))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sw/Module_sw.mk b/sw/Module_sw.mk
index 05a07c427841..e883a47cf59b 100644
--- a/sw/Module_sw.mk
+++ b/sw/Module_sw.mk
@@ -140,6 +140,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sw,\
     CppunitTest_sw_core_draw \
     CppunitTest_sw_core_edit \
     CppunitTest_sw_uibase_fldui \
+    CppunitTest_sw_core_attr \
 ))
 
 ifneq ($(DISABLE_GUI),TRUE)
diff --git a/sw/qa/core/attr/attr.cxx b/sw/qa/core/attr/attr.cxx
new file mode 100644
index 000000000000..0df9d9ef0451
--- /dev/null
+++ b/sw/qa/core/attr/attr.cxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <swmodeltestbase.hxx>
+
+#include <docsh.hxx>
+#include <swdtflvr.hxx>
+#include <swmodule.hxx>
+
+namespace
+{
+constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/core/attr/data/";
+
+/// Covers sw/source/core/attr/ fixes.
+class Test : public SwModelTestBase
+{
+};
+
+CPPUNIT_TEST_FIXTURE(Test, testSwAttrSet)
+{
+    // Given a document with track changes and the whole document is selected:
+    SwDoc* pDoc = createSwDoc(DATA_DIRECTORY, "attr-set.docx");
+    SwDocShell* pDocShell = pDoc->GetDocShell();
+    SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
+    dispatchCommand(mxComponent, ".uno:SelectAll", {});
+    dispatchCommand(mxComponent, ".uno:Cut", {});
+    dispatchCommand(mxComponent, ".uno:SelectAll", {});
+    rtl::Reference<SwTransferable> xTransferable(new 
SwTransferable(*pWrtShell));
+    SwModule* pMod = SW_MOD();
+    SwTransferable* pOldTransferable = pMod->m_pXSelection;
+    pMod->m_pXSelection = xTransferable.get();
+
+    // When getting the plain text version of the selection:
+    datatransfer::DataFlavor aFlavor;
+    aFlavor.MimeType = "text/plain;charset=utf-16";
+    aFlavor.DataType = cppu::UnoType<OUString>::get();
+    uno::Any aData = xTransferable->getTransferData(aFlavor);
+
+    // Then make sure we get data without crashing:
+    CPPUNIT_ASSERT(aData.hasValue());
+    pMod->m_pXSelection = pOldTransferable;
+}
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/qa/core/attr/data/attr-set.docx 
b/sw/qa/core/attr/data/attr-set.docx
new file mode 100644
index 000000000000..0cb8508aa2a4
Binary files /dev/null and b/sw/qa/core/attr/data/attr-set.docx differ
diff --git a/sw/source/core/attr/swatrset.cxx b/sw/source/core/attr/swatrset.cxx
index dea4ccfef5aa..b0909ca8b782 100644
--- a/sw/source/core/attr/swatrset.cxx
+++ b/sw/source/core/attr/swatrset.cxx
@@ -364,7 +364,8 @@ void SwAttrSet::CopyToModify( sw::BroadcastingModify& rMod 
) const
             }
 
             if (pSrcDoc != pDstDoc &&
-                SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, 
false, &pItem))
+                SfxItemState::SET == GetItemState(RES_PARATR_LIST_AUTOFMT, 
false, &pItem) &&
+                
pItem->StaticWhichCast(RES_PARATR_LIST_AUTOFMT).GetStyleHandle())
             {
                 SfxItemSet const& 
rAutoStyle(*pItem->StaticWhichCast(RES_PARATR_LIST_AUTOFMT).GetStyleHandle());
                 std::shared_ptr<SfxItemSet> const pNewSet(

Reply via email to