sw/source/core/layout/trvlfrm.cxx |   24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

New commits:
commit 66365b89f6f335e62db690add57482e91418c7d2
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Jun 23 12:27:34 2022 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Jun 24 10:10:54 2022 +0200

    sw: fix crash in SwLayoutFrame::GetContentPos
    
    FindPageFrame might return nullptr
    
    See 
https://crashreport.libreoffice.org/stats/signature/SwLayoutFrame::GetContentPos(Point%20&,bool,bool,SwCursorMoveState%20*,bool)
    
    Change-Id: Ic69d26de4ab234ebd6283ace640d689f0ebe8eb3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136307
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sw/source/core/layout/trvlfrm.cxx 
b/sw/source/core/layout/trvlfrm.cxx
index 6942dab6a2ba..375b9fe34fd6 100644
--- a/sw/source/core/layout/trvlfrm.cxx
+++ b/sw/source/core/layout/trvlfrm.cxx
@@ -1290,13 +1290,22 @@ const SwContentFrame *SwLayoutFrame::GetContentPos( 
Point& rPoint,
                     if( !pStart->GetPrev()->IsLayoutFrame() )
                         return nullptr;
                     pStart = static_cast<const 
SwLayoutFrame*>(pStart->GetPrev());
-                    pContent = pStart->IsInDocBody()
-                                ? pStart->ContainsContent()
-                                : 
pStart->FindPageFrame()->FindFirstBodyContent();
+                    if( pStart->IsInDocBody() )
+                        pContent = pStart->ContainsContent();
+                    else
+                    {
+                        const SwPageFrame *pPage = pStart->FindPageFrame();
+                        if( !pPage )
+                            return nullptr;
+                        pContent = pPage->FindFirstBodyContent();
+                    }
                 }
                 if ( !pContent )  // Somewhere down the road we have to start 
with one!
                 {
-                    pContent = 
pStart->FindPageFrame()->GetUpper()->ContainsContent();
+                    const SwPageFrame *pPage = pStart->FindPageFrame();
+                    if( !pPage )
+                        return nullptr;
+                    pContent = pPage->GetUpper()->ContainsContent();
                     while ( pContent && !pContent->IsInDocBody() )
                         pContent = pContent->GetNextContentFrame();
                     if ( !pContent )
@@ -1314,7 +1323,12 @@ const SwContentFrame *SwLayoutFrame::GetContentPos( 
Point& rPoint,
                     pContent = pStart->ContainsContent();
                 }
                 else // Somewhere down the road we have to start with one!
-                    pContent = 
pStart->FindPageFrame()->GetUpper()->ContainsContent();
+                {
+                    const SwPageFrame *pPage = pStart->FindPageFrame();
+                    if( !pPage )
+                        return nullptr;
+                    pContent = pPage->GetUpper()->ContainsContent();
+                }
             }
             pActual = pContent;
         }

Reply via email to