sc/source/core/data/dpsave.cxx |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

New commits:
commit 555d0dca78a261af8c18a9ab66e2456f272dff73
Author:     Eike Rathke <er...@redhat.com>
AuthorDate: Wed Sep 7 18:34:05 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Sep 8 11:31:28 2022 +0200

    crashtesting: prevent nullptr access
    
    There's a xlsx export crash on *2nd* export with data pilot data
    of forum-en-38962.ods. We export without crash this .ods to xlsx
    *once*, but on saving again to xlsx it crashes. It also crashes with an
    export to .xls and then an export to .xlsx. Repeated exports to xls are
    crash free.
    
    Already on the first export there are loads of warning messages of
    
    ScDPMember::GetItemData: what data? nDim 0, mnDataId #
    ScNameToIndexAccess getByIndex failed 
com.sun.star.container.NoSuchElementException message: "at 
sc/source/core/data/dptabsrc.cxx:2267
    
    The pivot tables are broken on both exports.
    
    This smells like some sort of data pilot cache
    corruption/insufficiency during .xlsx export but the root cause is
    yet unknown. This only fixes the crash symptom.
    
    Change-Id: Ie479f7f0abc4af284e61f6aa5a69943ccdd72eab
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139611
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins
    (cherry picked from commit 5aa3f046f934092fbfd7cc92b93d79b4f548cc13)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139565
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index 0f8bfbf11712..16de535bd85d 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -1285,8 +1285,20 @@ void 
ScDPSaveData::SyncAllDimensionMembers(ScDPTableData* pData)
         for (size_t j = 0; j < nMemberCount; ++j)
         {
             const ScDPItemData* pMemberData = pData->GetMemberById(nDimIndex, 
rMembers[j]);
-            OUString aMemName = pData->GetFormattedString(nDimIndex, 
*pMemberData, false);
-            aMemNames.insert(aMemName);
+            // ScDPCache::GetItemDataById() (via
+            // ScDPTableData::GetMemberById(),
+            // ScDPGroupTableData::GetMemberById() through
+            // GetCacheTable().getCache()) may return nullptr.
+            if (pMemberData)
+            {
+                OUString aMemName = pData->GetFormattedString(nDimIndex, 
*pMemberData, false);
+                aMemNames.insert(aMemName);
+            }
+            else
+            {
+                SAL_WARN("sc.core", "No pMemberData for nDimIndex " << 
nDimIndex << ", rMembers[j] " << rMembers[j]
+                        << ", j " << j);
+            }
         }
 
         it->RemoveObsoleteMembers(aMemNames);

Reply via email to