sc/CppunitTest_sc_uicalc.mk          |    5 ++++-
 sc/qa/unit/uicalc/data/tdf149503.xls |binary
 sc/qa/unit/uicalc/uicalc.cxx         |   21 +++++++++++++++++++++
 sc/source/core/data/dpoutput.cxx     |    4 ++++
 4 files changed, 29 insertions(+), 1 deletion(-)

New commits:
commit 50ee953b0edc571ac9518c3e1be9242b78df0554
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Fri Jun 10 10:04:15 2022 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Jun 13 17:06:33 2022 +0200

    tdf#149503: Check size of vectors
    
    Crash introduced by 41f95c4a35a6335e9edb2f51c11d136d88bd0749
    "Remove SC_DPOUT_MAXLEVELS limit in Pivot"
    
    This brings back the old behaviour and now the
    "You cannot change this part of the pivot table." message
    is displayed again
    
    Change-Id: Ibad84c0a279d7d67b709b7e311ac875739cdb210
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135578
    Tested-by: Eike Rathke <er...@redhat.com>
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135717
    Tested-by: Jenkins

diff --git a/sc/CppunitTest_sc_uicalc.mk b/sc/CppunitTest_sc_uicalc.mk
index e0df316fe3ab..e3ab3387ddd2 100644
--- a/sc/CppunitTest_sc_uicalc.mk
+++ b/sc/CppunitTest_sc_uicalc.mk
@@ -9,7 +9,10 @@
 
 $(eval $(call gb_CppunitTest_CppunitTest,sc_uicalc))
 
-$(eval $(call gb_CppunitTest_use_external,sc_uicalc,boost_headers))
+$(eval $(call gb_CppunitTest_use_externals,sc_uicalc, \
+       boost_headers \
+       mdds_headers \
+))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sc_uicalc, \
     sc/qa/unit/uicalc/uicalc \
diff --git a/sc/qa/unit/uicalc/data/tdf149503.xls 
b/sc/qa/unit/uicalc/data/tdf149503.xls
new file mode 100644
index 000000000000..88e4fb4ad651
Binary files /dev/null and b/sc/qa/unit/uicalc/data/tdf149503.xls differ
diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx
index beaf837bf1a4..872bc3a96c4a 100644
--- a/sc/qa/unit/uicalc/uicalc.cxx
+++ b/sc/qa/unit/uicalc/uicalc.cxx
@@ -27,6 +27,7 @@
 #include <document.hxx>
 #include <docuno.hxx>
 #include <docsh.hxx>
+#include <dpobject.hxx>
 #include <drwlayer.hxx>
 #include <inputopt.hxx>
 #include <postit.hxx>
@@ -645,6 +646,26 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf117706)
     CPPUNIT_ASSERT_EQUAL(OUString(""), pDoc->GetString(ScAddress(0, 2, 0)));
 }
 
+CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf149503)
+{
+    ScModelObj* pModelObj = createDoc("tdf149503.xls");
+    ScDocument* pDoc = pModelObj->GetDocument();
+    CPPUNIT_ASSERT(pDoc);
+
+    dispatchCommand(mxComponent, ".uno:SelectAll", {});
+    Scheduler::ProcessEventsToIdle();
+
+    dispatchCommand(mxComponent, ".uno:Cut", {});
+    Scheduler::ProcessEventsToIdle();
+
+    // Without the fix in place, this test would have crashed here
+    dispatchCommand(mxComponent, ".uno:Paste", {});
+    Scheduler::ProcessEventsToIdle();
+
+    ScDPCollection* pDPs = pDoc->GetDPCollection();
+    CPPUNIT_ASSERT_EQUAL(size_t(1), pDPs->GetCount());
+}
+
 // Inspired from testTdf117706, test columns instead of rows
 CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testMultiRangeCol)
 {
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index 1297fb136afb..aedbea61a044 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -1331,6 +1331,8 @@ void ScDPOutput::GetPositionData(const ScAddress& rPos, 
DataPilotTablePositionDa
             if (nField < 0)
                 break;
 
+            if (pColFields.size() < o3tl::make_unsigned(nField) + 1 )
+                break;
             const uno::Sequence<sheet::MemberResult> rSequence = 
pColFields[nField].maResult;
             if (!rSequence.hasElements())
                 break;
@@ -1360,6 +1362,8 @@ void ScDPOutput::GetPositionData(const ScAddress& rPos, 
DataPilotTablePositionDa
             if (nField < 0)
                 break;
 
+            if (pRowFields.size() < o3tl::make_unsigned(nField) + 1 )
+                break;
             const uno::Sequence<sheet::MemberResult> rSequence = 
pRowFields[nField].maResult;
             if (!rSequence.hasElements())
                 break;

Reply via email to