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

New commits:
commit e8763ec437f66926196707b803c60dc7032e6e0c
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Thu Jun 23 12:27:34 2022 +0200
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Sat Jun 25 21:22:42 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>
    (cherry picked from commit 7500c243fea02acbeaddf91f6b48a53d698c1cab)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136383
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

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