include/vcl/mapmod.hxx                                    |    2 ++
 vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz45583-1.svm |binary
 vcl/source/gdi/TypeSerializer.cxx                         |   13 ++++++++++---
 vcl/source/gdi/gdimtf.cxx                                 |   11 +++++++++--
 4 files changed, 21 insertions(+), 5 deletions(-)

New commits:
commit fcf785b82b92ecfff942577dafc27b1369c5e19c
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon Mar 21 16:15:31 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Tue Mar 22 16:02:12 2022 +0100

    ofz#45583 Integer-overflow on drawEPS
    
    Change-Id: I6a8add3e2ba695d2012916280a7f976b7b11934d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131908
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/include/vcl/mapmod.hxx b/include/vcl/mapmod.hxx
index 9af61f8b7e69..9d14fe60ae79 100644
--- a/include/vcl/mapmod.hxx
+++ b/include/vcl/mapmod.hxx
@@ -83,6 +83,8 @@ inline std::basic_ostream<charT, traits> & operator <<(
     return rStream;
 }
 
+bool TooLargeScaleForMapMode(const Fraction& rScale);
+
 #endif // INCLUDED_VCL_MAPMOD_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz45583-1.svm 
b/vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz45583-1.svm
new file mode 100644
index 000000000000..d730a1bccf4f
Binary files /dev/null and 
b/vcl/qa/cppunit/graphicfilter/data/svm/pass/ofz45583-1.svm differ
diff --git a/vcl/source/gdi/TypeSerializer.cxx 
b/vcl/source/gdi/TypeSerializer.cxx
index 829bc0503e1d..dfaf300c7801 100644
--- a/vcl/source/gdi/TypeSerializer.cxx
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -425,10 +425,8 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic)
     }
 }
 
-static bool UselessScaleForMapMode(const Fraction& rScale)
+bool TooLargeScaleForMapMode(const Fraction& rScale)
 {
-    if (!rScale.IsValid())
-        return true;
     // ImplLogicToPixel will multiply its values by this numerator * dpi and 
then double that
     // result before dividing
     constexpr sal_Int32 nTypicalDPI = 96;
@@ -436,6 +434,15 @@ static bool UselessScaleForMapMode(const Fraction& rScale)
         return true;
     if (rScale.GetNumerator() < std::numeric_limits<sal_Int32>::min() / 
nTypicalDPI / 2)
         return true;
+    return false;
+}
+
+static bool UselessScaleForMapMode(const Fraction& rScale)
+{
+    if (!rScale.IsValid())
+        return true;
+    if (TooLargeScaleForMapMode(rScale))
+        return true;
     if (static_cast<double>(rScale) < 0.0)
         return true;
     return false;
diff --git a/vcl/source/gdi/gdimtf.cxx b/vcl/source/gdi/gdimtf.cxx
index a747e55f5685..dd682420c1eb 100644
--- a/vcl/source/gdi/gdimtf.cxx
+++ b/vcl/source/gdi/gdimtf.cxx
@@ -478,8 +478,15 @@ void GDIMetaFile::Play(OutputDevice& rOut, const Point& 
rPos,
     Fraction aScaleX( aDestSize.Width(), aTmpPrefSize.Width() );
     Fraction aScaleY( aDestSize.Height(), aTmpPrefSize.Height() );
 
-    aScaleX *= aDrawMap.GetScaleX(); aDrawMap.SetScaleX( aScaleX );
-    aScaleY *= aDrawMap.GetScaleY(); aDrawMap.SetScaleY( aScaleY );
+    aScaleX *= aDrawMap.GetScaleX();
+    if (TooLargeScaleForMapMode(aScaleX))
+        aScaleX.ReduceInaccurate(10);
+    aScaleY *= aDrawMap.GetScaleY();
+    if (TooLargeScaleForMapMode(aScaleY))
+        aScaleY.ReduceInaccurate(10);
+
+    aDrawMap.SetScaleX(aScaleX);
+    aDrawMap.SetScaleY(aScaleY);
 
     // #i47260# Convert logical output position to offset within
     // the metafile's mapmode. Therefore, disable pixel offset on

Reply via email to