sc/source/core/data/documen3.cxx |    3 ++-
 sc/source/core/data/documen5.cxx |    3 +++
 sc/source/core/data/document.cxx |    4 ++--
 sc/source/ui/docshell/docsh.cxx  |   10 ++--------
 sc/source/ui/docshell/docsh2.cxx |   31 +++++++++++++++++--------------
 sc/source/ui/inc/docsh.hxx       |    3 +--
 sc/source/ui/view/viewfun5.cxx   |   10 +++++-----
 7 files changed, 32 insertions(+), 32 deletions(-)

New commits:
commit 1928987f0d26f9475f1a2bcf94702fc6c614cf70
Author:     Mike Kaganski <[email protected]>
AuthorDate: Tue Dec 23 13:16:38 2025 +0100
Commit:     Balazs Varga <[email protected]>
CommitDate: Tue Mar 3 08:41:30 2026 +0100

    tdf#127675: SfxObjectShell::DoLoad takes ownership of the passed medium
    
    Implementation defect from commit ba49c9249fcfec8891ef7d53dc8c9db1715df020
    (tdf#127675 Treat Biff12 when pasting, 2025-11-16).
    
    I don't know how to produce a unit test for this...
    
    cherry-picked from: a616d6f20f95735d4db4af1c102b40c9c98c2080
    
    Change-Id: I82a5f1c7cbd1e9d0cc32f8a9c5d62bade2911afc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196161
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200392
    Tested-by: allotropia jenkins <[email protected]>
    Tested-by: Gabor Kelemen <[email protected]>
    Reviewed-by: Balazs Varga <[email protected]>

diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx
index 785f524ff711..99e99457f77d 100644
--- a/sc/source/ui/view/viewfun5.cxx
+++ b/sc/source/ui/view/viewfun5.cxx
@@ -604,11 +604,11 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId 
nFormatId,
                 ScDocShellRef pClipShell(new ScDocShell(SfxModelFlags::NONE, 
SCDOCMODE_CLIP));
                 SCTAB nSrcTab = 0;
                 pClipShell->GetDocument().ResetClip(pDoc, nSrcTab);
-                SfxMedium aMed;
-                aMed.GetItemSet()->Put(SfxUnoAnyItem(SID_INPUTSTREAM, 
uno::Any(xStm)));
-                aMed.SetFilter(pFilter);
+                auto pMed = std::make_unique<SfxMedium>();
+                pMed->GetItemSet()->Put(SfxUnoAnyItem(SID_INPUTSTREAM, 
uno::Any(xStm)));
+                pMed->SetFilter(pFilter);
 
-                if (pClipShell->DoLoad(&aMed))
+                if (pClipShell->DoLoad(pMed.release()))
                 {
                     PasteFromExcelClip(pClipShell->GetDocument(), nSrcTab, 
nPosX, nPosY, pLogicPos,
                                        bAllowDialogs);
commit aaf203966a297b00814e04f256e6a3fe608d243c
Author:     Balazs Varga <[email protected]>
AuthorDate: Thu Feb 26 09:06:09 2026 +0100
Commit:     Balazs Varga <[email protected]>
CommitDate: Tue Mar 3 08:41:19 2026 +0100

    Related: tdf#127675 Treat Biff12 when pasting
    
    follow-up of 04e2c1a2e9d3148bc1f652d6a50275352c5568b0
    which tried to backport a clipboard fix from master
    ba49c9249fcfec8891ef7d53dc8c9db1715df020
    
    Also backport null-check guards from master commit
    964e2eaae9d32df201574e6f083acc630fed2f1d
    (tdf#142635) to protect against uninitialized mxPoolHelper
    in SCDOCMODE_CLIP
    
    When ScDocShell is created with SCDOCMODE_CLIP for BIFF12 paste,
    ScDocument does not initialize mxPoolHelper (only SCDOCMODE_DOCUMENT
    and SCDOCMODE_FUNCTIONACCESS do). The ScDocShell constructor accesses
    GetStyleSheetPool() before ResetClip() has a chance to share the pool
    from the source document, causing a null pointer dereference crash.
    
    Change-Id: I247ab90757b36da30d90ce45a7dc65e396d21a5f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200391
    Reviewed-by: Balazs Varga <[email protected]>
    Tested-by: allotropia jenkins <[email protected]>
    Tested-by: Gabor Kelemen <[email protected]>

diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 783bac66f2fd..5f5106fe6cb1 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1913,7 +1913,8 @@ void ScDocument::SetDocOptions( const ScDocOptions& rOpt )
     assert(pDocOptions && "No DocOptions! :-(");
 
     *pDocOptions = rOpt;
-    mxPoolHelper->SetFormTableOpt(rOpt);
+    if (mxPoolHelper)
+        mxPoolHelper->SetFormTableOpt(rOpt);
 }
 
 const ScViewOptions& ScDocument::GetViewOptions() const
diff --git a/sc/source/core/data/documen5.cxx b/sc/source/core/data/documen5.cxx
index 2000121fa892..215e48c01beb 100644
--- a/sc/source/core/data/documen5.cxx
+++ b/sc/source/core/data/documen5.cxx
@@ -361,6 +361,9 @@ void ScDocument::UpdateChart( const OUString& rChartName )
 
 void ScDocument::RestoreChartListener( const OUString& rName )
 {
+    if (!pChartListenerCollection)
+        return;
+
     // Read the data ranges from the chart object, and start listening to 
those ranges again
     // (called when a chart is saved, because then it might be swapped out and 
stop listening itself).
 
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 3f1a41f908a3..9c8493d5d462 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6042,12 +6042,12 @@ ScPatternAttr* ScDocument::GetDefPattern() const
 
 ScDocumentPool* ScDocument::GetPool()
 {
-    return mxPoolHelper->GetDocPool();
+    return mxPoolHelper ? mxPoolHelper->GetDocPool() : nullptr;
 }
 
 ScStyleSheetPool* ScDocument::GetStyleSheetPool() const
 {
-    return mxPoolHelper->GetStylePool();
+    return mxPoolHelper ? mxPoolHelper->GetStylePool() : nullptr;
 }
 
 SCSIZE ScDocument::GetEmptyLinesInBlock( SCCOL nStartCol, SCROW nStartRow, 
SCTAB nStartTab,
diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx
index c0442bdd3cc5..8937d0dfc67c 100644
--- a/sc/source/ui/docshell/docsh.cxx
+++ b/sc/source/ui/docshell/docsh.cxx
@@ -2733,15 +2733,9 @@ std::unique_ptr<ScDocFunc> ScDocShell::CreateDocFunc()
     return std::make_unique<ScDocFuncDirect>( *this );
 }
 
-/*ScDocShell::ScDocShell(const SfxModelFlags i_nSfxCreationFlags, 
ScDocumentMode docMode)
-    : ScDocShell(i_nSfxCreationFlags, std::make_shared<ScDocument>(docMode, 
this))
-{
-}
-*/
-
-ScDocShell::ScDocShell( const SfxModelFlags i_nSfxCreationFlags ) :
+ScDocShell::ScDocShell( const SfxModelFlags i_nSfxCreationFlags, 
ScDocumentMode docMode ) :
     SfxObjectShell( i_nSfxCreationFlags ),
-    m_aDocument       ( SCDOCMODE_DOCUMENT, this ),
+    m_aDocument       ( docMode, this ),
     m_aDdeTextFmt(OUString("TEXT")),
     m_nPrtToScreenFactor( 1.0 ),
     m_pImpl           ( new DocShell_Impl ),
diff --git a/sc/source/ui/docshell/docsh2.cxx b/sc/source/ui/docshell/docsh2.cxx
index 3749d4eff038..4697a3d56712 100644
--- a/sc/source/ui/docshell/docsh2.cxx
+++ b/sc/source/ui/docshell/docsh2.cxx
@@ -55,24 +55,27 @@ bool ScDocShell::InitNew( const uno::Reference < 
embed::XStorage >& xStor )
     // InitOptions sets the document languages, must be called before 
CreateStandardStyles
     InitOptions(false);
 
-    m_aDocument.GetStyleSheetPool()->CreateStandardStyles();
-    m_aDocument.UpdStlShtPtrsFrmNms();
-
-    if (!m_bUcalcTest)
+    if (ScStyleSheetPool* pStyleSheetPool = m_aDocument.GetStyleSheetPool())
     {
-        /* Create styles that are imported through Orcus */
+        pStyleSheetPool->CreateStandardStyles();
+        m_aDocument.UpdStlShtPtrsFrmNms();
 
-        OUString aURL("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/calc/styles.xml");
-        rtl::Bootstrap::expandMacros(aURL);
+        if (!m_bUcalcTest)
+        {
+            /* Create styles that are imported through Orcus */
 
-        OUString aPath;
-        osl::FileBase::getSystemPathFromFileURL(aURL, aPath);
+            OUString aURL("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER 
"/calc/styles.xml");
+            rtl::Bootstrap::expandMacros(aURL);
 
-        ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
-        if (pOrcus)
-        {
-            pOrcus->importODS_Styles(m_aDocument, aPath);
-            m_aDocument.GetStyleSheetPool()->setAllStandard();
+            OUString aPath;
+            osl::FileBase::getSystemPathFromFileURL(aURL, aPath);
+
+            ScOrcusFilters* pOrcus = ScFormatFilter::Get().GetOrcusFilters();
+            if (pOrcus)
+            {
+                pOrcus->importODS_Styles(m_aDocument, aPath);
+                pStyleSheetPool->setAllStandard();
+            }
         }
     }
 
diff --git a/sc/source/ui/inc/docsh.hxx b/sc/source/ui/inc/docsh.hxx
index 5851ed9449ec..994949b663a7 100644
--- a/sc/source/ui/inc/docsh.hxx
+++ b/sc/source/ui/inc/docsh.hxx
@@ -171,8 +171,7 @@ private:
 
 public:
     explicit        ScDocShell( const ScDocShell& rDocShell ) = delete;
-    explicit        ScDocShell( const SfxModelFlags i_nSfxCreationFlags = 
SfxModelFlags::EMBEDDED_OBJECT );
-//    explicit ScDocShell(const SfxModelFlags i_nSfxCreationFlags, 
ScDocumentMode);
+    explicit        ScDocShell( const SfxModelFlags i_nSfxCreationFlags = 
SfxModelFlags::EMBEDDED_OBJECT, ScDocumentMode = SCDOCMODE_DOCUMENT );
                     virtual ~ScDocShell() override;
 
     virtual SfxUndoManager*
diff --git a/sc/source/ui/view/viewfun5.cxx b/sc/source/ui/view/viewfun5.cxx
index 251c945b06ad..785f524ff711 100644
--- a/sc/source/ui/view/viewfun5.cxx
+++ b/sc/source/ui/view/viewfun5.cxx
@@ -601,7 +601,7 @@ bool ScViewFunc::PasteDataFormat( SotClipboardFormatId 
nFormatId,
             SfxFilterMatcher 
aMatcher(ScDocShell::Factory().GetFilterContainer()->GetName());
             if (auto pFilter = 
aMatcher.GetFilter4ClipBoardId(SotClipboardFormatId::BIFF_12))
             {
-                ScDocShellRef pClipShell(new ScDocShell(SfxModelFlags::NONE));
+                ScDocShellRef pClipShell(new ScDocShell(SfxModelFlags::NONE, 
SCDOCMODE_CLIP));
                 SCTAB nSrcTab = 0;
                 pClipShell->GetDocument().ResetClip(pDoc, nSrcTab);
                 SfxMedium aMed;

Reply via email to