summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2022-06-10 10:04:15 +0200
committerEike Rathke <erack@redhat.com>2022-06-13 17:06:33 +0200
commit50ee953b0edc571ac9518c3e1be9242b78df0554 (patch)
tree61df05f9c16fd2389afed1c4d48262e015373414 /sc
parent8875411275808f24668057c6b95a5ed726ae5631 (diff)
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 <erack@redhat.com> Reviewed-by: Eike Rathke <erack@redhat.com> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135717 Tested-by: Jenkins
Diffstat (limited to 'sc')
-rw-r--r--sc/CppunitTest_sc_uicalc.mk5
-rw-r--r--sc/qa/unit/uicalc/data/tdf149503.xlsbin0 -> 43008 bytes
-rw-r--r--sc/qa/unit/uicalc/uicalc.cxx21
-rw-r--r--sc/source/core/data/dpoutput.cxx4
4 files changed, 29 insertions, 1 deletions
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
--- /dev/null
+++ b/sc/qa/unit/uicalc/data/tdf149503.xls
Binary files 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;