sc/qa/unit/data/xlsx/forcepoint107.xlsx |binary
 sc/qa/unit/filters-test.cxx             |    9 +++++++++
 sc/source/core/data/documentimport.cxx  |    8 ++++++++
 sc/source/core/data/formulacell.cxx     |    3 +++
 4 files changed, 20 insertions(+)

New commits:
commit 6721eddbcfefd9503a49499956e53d1a76f6712f
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Tue Jun 21 10:38:30 2022 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Wed Jul 20 10:00:39 2022 +0200

    forcepoint#107: reproducible testcase
    
    make this reproducible without asan
    
    Change-Id: I32cee0a22616e96d85c59d76319a6f6074fcde8b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136228
    Tested-by: Jenkins
    Tested-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sc/qa/unit/data/xlsx/forcepoint107.xlsx 
b/sc/qa/unit/data/xlsx/forcepoint107.xlsx
new file mode 100644
index 000000000000..f5238dcb5c3e
Binary files /dev/null and b/sc/qa/unit/data/xlsx/forcepoint107.xlsx differ
diff --git a/sc/qa/unit/filters-test.cxx b/sc/qa/unit/filters-test.cxx
index 9c14df33b862..44aadbbba7b7 100644
--- a/sc/qa/unit/filters-test.cxx
+++ b/sc/qa/unit/filters-test.cxx
@@ -82,6 +82,7 @@ public:
     void testSortWithSheetExternalReferencesODS_Impl( ScDocShellRef const & 
xDocShRef, SCROW nRow1, SCROW nRow2,
             bool bCheckRelativeInSheet );
     void testSortWithFormattingXLS();
+    void testForcepoint107();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
     CPPUNIT_TEST(testCVEs);
@@ -108,6 +109,7 @@ public:
     CPPUNIT_TEST(testSortWithSharedFormulasODS);
     CPPUNIT_TEST(testSortWithSheetExternalReferencesODS);
     CPPUNIT_TEST(testSortWithFormattingXLS);
+    CPPUNIT_TEST(testForcepoint107);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -869,6 +871,13 @@ void ScFiltersTest::testSortWithFormattingXLS()
     xDocSh->DoClose();
 }
 
+// just needs to not crash on recalc
+void ScFiltersTest::testForcepoint107()
+{
+    ScDocShellRef xDocSh = loadDoc(u"forcepoint107.", FORMAT_XLSX, true);
+    xDocSh->DoHardRecalc();
+}
+
 ScFiltersTest::ScFiltersTest()
     : ScBootstrapFixture( "sc/qa/unit/data" )
     , mbUpdateReferenceOnSort(false)
diff --git a/sc/source/core/data/documentimport.cxx 
b/sc/source/core/data/documentimport.cxx
index 5a2e77e66ffb..9f2af767b42f 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -385,6 +385,14 @@ void ScDocumentImport::setFormulaCell(const ScAddress& 
rPos, ScFormulaCell* pCel
         mpImpl->mrDoc.CheckLinkFormulaNeedingCheck( *pCell->GetCode());
 
     sc::CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
+
+    sc::CellStoreType::position_type aPos = rCells.position(rPos.Row());
+    if (aPos.first != rCells.end() && aPos.first->type == 
sc::element_type_formula)
+    {
+        ScFormulaCell* p = sc::formula_block::at(*aPos.first->data, 
aPos.second);
+        sc::SharedFormulaUtil::unshareFormulaCell(aPos, *p);
+    }
+
     pBlockPos->miCellPos =
         rCells.set(pBlockPos->miCellPos, rPos.Row(), pCell);
 }
diff --git a/sc/source/core/data/formulacell.cxx 
b/sc/source/core/data/formulacell.cxx
index e44e0e47a9a9..7e0400514122 100644
--- a/sc/source/core/data/formulacell.cxx
+++ b/sc/source/core/data/formulacell.cxx
@@ -925,6 +925,9 @@ ScFormulaCell::~ScFormulaCell()
     if (!mxGroup || !mxGroup->mpCode)
         // Formula token is not shared.
         delete pCode;
+
+    if (mxGroup && mxGroup->mpTopCell == this)
+        mxGroup->mpTopCell = nullptr;
 }
 
 ScFormulaCell* ScFormulaCell::Clone() const

Reply via email to