[Libreoffice-commits] core.git: emfio/source filter/source sc/source sd/source sfx2/source svtools/source sw/source vcl/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 16 07:12:21 UTC 2020


 emfio/source/reader/emfreader.cxx           |    6 ++++++
 emfio/source/reader/wmfreader.cxx           |    6 ++++++
 filter/source/graphicfilter/ipict/ipict.cxx |    7 +++++++
 sc/source/ui/view/tabview3.cxx              |    4 ++--
 sd/source/ui/view/viewshel.cxx              |    2 ++
 sfx2/source/sidebar/Deck.cxx                |    2 ++
 svtools/source/control/ruler.cxx            |    4 ++--
 sw/source/uibase/uiview/view.cxx            |    2 +-
 vcl/source/control/scrbar.cxx               |    7 +++++--
 9 files changed, 33 insertions(+), 7 deletions(-)

New commits:
commit 059f07f9f33460c809a93e0fda1165f5c6f6d805
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Apr 15 18:34:58 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Apr 16 09:11:41 2020 +0200

    fixes for code creating reversed Rectangles
    
    ie. where left > right or top > bottom
    
    These are all places where the code is self-evidently doing the wrong
    thing.
    
    Found by adding asserts to tools::Rectangle. In theory, this is legit,
    and code that wants a proper Rectangle is supposed to be first call
    Justify on a Rectangle, but lots of places don't do that, and that seems
    very dodgy to me.
    
    So lets work towards Rectangles always being in a valid state.
    
    Change-Id: I03296a624bd9b5b193e6aa8778addfb09708cdc7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92310
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/emfio/source/reader/emfreader.cxx b/emfio/source/reader/emfreader.cxx
index 35a5f020d0fa..252015bab2e6 100644
--- a/emfio/source/reader/emfreader.cxx
+++ b/emfio/source/reader/emfreader.cxx
@@ -2088,6 +2088,12 @@ namespace emfio
         mpInputStream->ReadInt32(nBottom);
 
         SAL_INFO("emfio", "\t\tLeft: " << nLeft << ", top: " << nTop << ", right: " << nRight << ", bottom: " << nBottom);
+        if (nLeft > nRight || nTop > nBottom)
+        {
+            SAL_WARN("emfio", "broken rectangle");
+            mpInputStream->SetError( SVSTREAM_FILEFORMAT_ERROR );
+            return tools::Rectangle();
+        }
 
         return tools::Rectangle(nLeft, nTop, nRight, nBottom);
     }
diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx
index 1d67f5c52e98..3f8af75bbd50 100644
--- a/emfio/source/reader/wmfreader.cxx
+++ b/emfio/source/reader/wmfreader.cxx
@@ -165,6 +165,12 @@ namespace emfio
         aTL = ReadYX();
         aBR.AdjustX( -1 );
         aBR.AdjustY( -1 );
+        if (aTL.X() > aBR.X() || aTL.Y() > aBR.Y())
+        {
+            SAL_WARN("vcl.wmf", "broken rectangle");
+            mpInputStream->SetError( SVSTREAM_FILEFORMAT_ERROR );
+            return tools::Rectangle();
+        }
         return tools::Rectangle( aTL, aBR );
     }
 
diff --git a/filter/source/graphicfilter/ipict/ipict.cxx b/filter/source/graphicfilter/ipict/ipict.cxx
index 58ec7423de8f..d494543fb1b4 100644
--- a/filter/source/graphicfilter/ipict/ipict.cxx
+++ b/filter/source/graphicfilter/ipict/ipict.cxx
@@ -454,6 +454,13 @@ void PictReader::ReadRectangle(tools::Rectangle & rRect)
 
     aTopLeft=ReadPoint();
     aBottomRight=ReadPoint();
+    if (aTopLeft.X() > aBottomRight.X() || aTopLeft.Y() > aBottomRight.Y())
+    {
+        SAL_WARN("filter.pict", "broken rectangle");
+        pPict->SetError( SVSTREAM_FILEFORMAT_ERROR );
+        rRect = tools::Rectangle();
+        return;
+    }
     rRect=tools::Rectangle(aTopLeft,aBottomRight);
 
     SAL_INFO("filter.pict", "ReadRectangle: " << rRect);
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index fa68182b2399..cfff46935dad 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -2674,7 +2674,7 @@ void ScTabView::PaintTopArea( SCCOL nStartCol, SCCOL nEndCol )
             long nStartX = aViewData.GetScrPos( nStartCol, 0, eWhich ).X();
             long nEndX;
             if (nEndCol >= pDoc->MaxCol())
-                nEndX = bLayoutRTL ? 0 : ( aWinSize.Width()-1 );
+                nEndX = nStartX + (bLayoutRTL ? 0 : ( aWinSize.Width()-1 ));
             else
                 nEndX = aViewData.GetScrPos( nEndCol+1, 0, eWhich ).X() - nLayoutSign;
             pColBar[eWhich]->Invalidate(
@@ -2727,7 +2727,7 @@ void ScTabView::PaintLeftArea( SCROW nStartRow, SCROW nEndRow )
             long nStartY = aViewData.GetScrPos( 0, nStartRow, eWhich ).Y();
             long nEndY;
             if (nEndRow >= pDoc->MaxRow())
-                nEndY = aWinSize.Height()-1;
+                nEndY = nStartY + aWinSize.Height() - 1;
             else
                 nEndY = aViewData.GetScrPos( 0, nEndRow+1, eWhich ).Y() - 1;
             pRowBar[eWhich]->Invalidate(
diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx
index 9ef01355849c..97719c049e32 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -929,6 +929,8 @@ void ViewShell::ArrangeGUIElements()
 {
     if (mpImpl->mbArrangeActive)
         return;
+    if (maViewSize.IsEmpty())
+        return;
     mpImpl->mbArrangeActive = true;
 
     // Calculate border for in-place editing.
diff --git a/sfx2/source/sidebar/Deck.cxx b/sfx2/source/sidebar/Deck.cxx
index 3bfb21134e3b..d874ba59b92d 100644
--- a/sfx2/source/sidebar/Deck.cxx
+++ b/sfx2/source/sidebar/Deck.cxx
@@ -110,6 +110,8 @@ tools::Rectangle Deck::GetContentArea() const
 {
     const Size aWindowSize (GetSizePixel());
     const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize));
+    if (aWindowSize.IsEmpty())
+        return tools::Rectangle();
 
     return tools::Rectangle(
         Theme::GetInteger(Theme::Int_DeckLeftPadding) + nBorderSize,
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx
index a4f30d9c97a7..8608adc3b7fc 100644
--- a/svtools/source/control/ruler.cxx
+++ b/svtools/source/control/ruler.cxx
@@ -594,8 +594,8 @@ void Ruler::ImplDrawTicks(vcl::RenderContext& rRenderContext, long nMin, long nM
 
                 if (nMin < nHorizontalLocation && nHorizontalLocation < nMax)
                 {
-                    ImplVDrawRect(rRenderContext, nHorizontalLocation, nBottom, nHorizontalLocation + DPIOffset, nBottom - 1 * nScale);
-                    ImplVDrawRect(rRenderContext, nHorizontalLocation, nTop,    nHorizontalLocation + DPIOffset, nTop + 1 * nScale);
+                    ImplVDrawRect(rRenderContext, nHorizontalLocation, nBottom - 1 * nScale, nHorizontalLocation + DPIOffset, nBottom);
+                    ImplVDrawRect(rRenderContext, nHorizontalLocation, nTop, nHorizontalLocation + DPIOffset, nTop + 1 * nScale);
                 }
 
                 nHorizontalLocation = nStart - n;
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index 5f34e355bb17..f2d10b466dce 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -1290,7 +1290,7 @@ void SwView::ReadUserDataSequence ( const uno::Sequence < beans::PropertyValue >
     const SwViewOption* pVOpt = m_pWrtShell->GetViewOptions();
 
     sal_Int64 nX = rRect.Left(), nY = rRect.Top(), nLeft = rVis.Left(), nTop = rVis.Top();
-    sal_Int64 nRight = LONG_MIN;
+    sal_Int64 nRight = nLeft;
     sal_Int64 nBottom = LONG_MIN;
     sal_Int16 nZoomType = static_cast< sal_Int16 >(pVOpt->GetZoomType());
     sal_Int16 nZoomFactor = static_cast < sal_Int16 > (pVOpt->GetZoom());
diff --git a/vcl/source/control/scrbar.cxx b/vcl/source/control/scrbar.cxx
index e0a11cf877b6..976a5b452c97 100644
--- a/vcl/source/control/scrbar.cxx
+++ b/vcl/source/control/scrbar.cxx
@@ -269,7 +269,7 @@ void ScrollBar::ImplCalc( bool bUpdate )
                      aControlRegion, ControlState::NONE, ImplControlValue(), aBoundingRegion, aTrackRegion ) )
                 maTrackRect = aTrackRegion;
             else
-                maTrackRect = tools::Rectangle( maBtn1Rect.TopRight(), maBtn2Rect.BottomLeft() );
+                maTrackRect = maBtn1Rect;
 
             // Check if available space is big enough for thumb ( min thumb size = ScrBar width/height )
             mnThumbPixRange = maTrackRect.Right() - maTrackRect.Left();
@@ -306,7 +306,10 @@ void ScrollBar::ImplCalc( bool bUpdate )
                      aControlRegion, ControlState::NONE, ImplControlValue(), aBoundingRegion, aTrackRegion ) )
                 maTrackRect = aTrackRegion;
             else
-                maTrackRect = tools::Rectangle( maBtn1Rect.BottomLeft()+Point(0,1), maBtn2Rect.TopRight() );
+            {
+                maTrackRect = maBtn1Rect;
+                maTrackRect.AdjustTop(1);
+            }
 
             // Check if available space is big enough for thumb
             mnThumbPixRange = maTrackRect.Bottom() - maTrackRect.Top();


More information about the Libreoffice-commits mailing list