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

New commits:
commit 538f86a1a512b67b7abbe7edbc62acf341eb6606
Author:     Eike Rathke <[email protected]>
AuthorDate: Wed Sep 7 18:34:05 2022 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Fri Sep 9 19:17:02 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 <[email protected]>
    Tested-by: Jenkins
    (cherry picked from commit 5aa3f046f934092fbfd7cc92b93d79b4f548cc13)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139565
    Reviewed-by: Xisco Fauli <[email protected]>
    (cherry picked from commit 0f434e0b91e240ff60418da4ae9c6415554e4d0f)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139572
    Reviewed-by: Christian Lohmaier <[email protected]>
    Tested-by: Xisco Fauli <[email protected]>

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