summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2012-07-24 10:53:33 +0200
committerMichael Stahl <mstahl@redhat.com>2012-07-24 15:08:42 +0200
commitb1af9e14759f752689c26f8426a76c35e57064f3 (patch)
tree8af464bb96463044aaeb74361abfa33cbfefd0ae
parent524caf98ca542668df91ee214c970ba50fc3f268 (diff)
prevent crash in malformed pivot table loaded from .xls
ScDPMember::GetItemData() unconditionally returned a reference to a ScDPItemData pointer obtained through ScDPSource::GetItemDataById() ScDPTableData::GetMemberById() ScDPCache::GetItemDataById() that can be null for malformed entries. Changed ScDPMember::GetItemData() to return a pointer instead and adapted callers to check for null. 3.5.x in ScDPSource::GetItemDataById() had a check for null pointer and added an empty ScDPItemData element to the cache for this case and returned the pointer to that entry (marked as todo). This is not the case anymore. (cherry picked from commit 3536fcd999f16525f20a1fff5c2512b565511d7b plus follow-up 9b2ec8c2a3478047a270b31bc25ad1d782401306 "it's pData2") Change-Id: I241c232d7182f5d58e8531af540e69b26ab4888a Signed-off-by: Stephan Bergmann <sbergman@redhat.com> (cherry picked from commit ca9607ac8ed43d29125a0a2d22a938ec8f414841) Signed-off-by: Petr Mladek <pmladek@suse.cz> Signed-off-by: Michael Stahl <mstahl@redhat.com>
-rw-r--r--sc/inc/dptabsrc.hxx2
-rw-r--r--sc/source/core/data/dptabsrc.cxx17
2 files changed, 13 insertions, 6 deletions
diff --git a/sc/inc/dptabsrc.hxx b/sc/inc/dptabsrc.hxx
index b69846b48f31..9fced306c11b 100644
--- a/sc/inc/dptabsrc.hxx
+++ b/sc/inc/dptabsrc.hxx
@@ -755,7 +755,7 @@ public:
rtl::OUString GetNameStr() const;
void FillItemData( ScDPItemData& rData ) const;
- const ScDPItemData& GetItemData() const;
+ const ScDPItemData* GetItemData() const;
SCROW GetItemDataId() const { return mnDataId; }
bool IsNamedItem(SCROW nIndex) const;
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index 4d680aeedcae..bbf92170e6e2 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -2583,7 +2583,8 @@ bool ScDPMember::IsNamedItem(SCROW nIndex) const
(long)::rtl::math::approxFloor( pData->GetValue() ),
nHier, nLev );
// fValue is converted from integer, so simple comparison works
- return nComp == GetItemData().GetValue();
+ const ScDPItemData* pData2 = GetItemData();
+ return pData2 && nComp == pData2->GetValue();
}
}
@@ -2619,7 +2620,8 @@ void ScDPMember::FillItemData( ScDPItemData& rData ) const
{
//! handle date hierarchy...
- rData = GetItemData() ;
+ const ScDPItemData* pData = GetItemData();
+ rData = (pData ? *pData : ScDPItemData());
}
const OUString* ScDPMember::GetLayoutName() const
@@ -2634,7 +2636,10 @@ long ScDPMember::GetDim() const
rtl::OUString ScDPMember::GetNameStr() const
{
- return pSource->GetData()->GetFormattedString(nDim, GetItemData());
+ const ScDPItemData* pData = GetItemData();
+ if (pData)
+ return pSource->GetData()->GetFormattedString(nDim, *pData);
+ return rtl::OUString();
}
::rtl::OUString SAL_CALL ScDPMember::getName() throw(uno::RuntimeException)
@@ -2729,9 +2734,11 @@ const ScDPCache* ScDPSource::GetCache()
return ( GetData()!=NULL) ? GetData()->GetCacheTable().getCache() : NULL ;
}
-const ScDPItemData& ScDPMember::GetItemData() const
+const ScDPItemData* ScDPMember::GetItemData() const
{
- return *pSource->GetItemDataById(nDim, mnDataId);
+ const ScDPItemData* pData = pSource->GetItemDataById(nDim, mnDataId);
+ SAL_WARN_IF( !pData, "sc", "ScDPMember::GetItemData: what data? nDim " << nDim << ", mnDataId " << mnDataId);
+ return pData;
}
const ScDPItemData* ScDPSource::GetItemDataById(long nDim, long nId)