summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-03-18 19:50:12 +0000
committerCaolán McNamara <caolanm@redhat.com>2022-03-19 21:52:01 +0100
commit32dc2d14287a4210589c33dbd62c6e36e095aa6e (patch)
tree4ba6803f35bae2bcc6a8ef3e111e77126dab15be
parentef37fa084e55aa13ecebcd0ebdbc7c2bca908c11 (diff)
ofz#45583 detect some invalid scale cases at import time
Change-Id: Iad881f09bef707897e19d402a9931a6dea88f52d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131839 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--vcl/source/gdi/TypeSerializer.cxx21
1 files changed, 17 insertions, 4 deletions
diff --git a/vcl/source/gdi/TypeSerializer.cxx b/vcl/source/gdi/TypeSerializer.cxx
index fb054e4748ef..829bc0503e1d 100644
--- a/vcl/source/gdi/TypeSerializer.cxx
+++ b/vcl/source/gdi/TypeSerializer.cxx
@@ -425,6 +425,22 @@ void TypeSerializer::writeGraphic(const Graphic& rGraphic)
}
}
+static bool UselessScaleForMapMode(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;
+ if (rScale.GetNumerator() > std::numeric_limits<sal_Int32>::max() / nTypicalDPI / 2)
+ return true;
+ if (rScale.GetNumerator() < std::numeric_limits<sal_Int32>::min() / nTypicalDPI / 2)
+ return true;
+ if (static_cast<double>(rScale) < 0.0)
+ return true;
+ return false;
+}
+
void TypeSerializer::readMapMode(MapMode& rMapMode)
{
VersionCompatRead aCompat(mrStream);
@@ -441,10 +457,7 @@ void TypeSerializer::readMapMode(MapMode& rMapMode)
readFraction(aScaleY);
mrStream.ReadCharAsBool(bSimple);
- const bool bBogus = !aScaleX.IsValid() || !aScaleY.IsValid()
- || aScaleX.GetNumerator() == std::numeric_limits<sal_Int32>::min()
- || aScaleY.GetNumerator() == std::numeric_limits<sal_Int32>::min()
- || static_cast<double>(aScaleX) < 0.0 || static_cast<double>(aScaleY) < 0.0;
+ const bool bBogus = UselessScaleForMapMode(aScaleX) || UselessScaleForMapMode(aScaleY);
SAL_WARN_IF(bBogus, "vcl", "invalid scale");
if (bSimple || bBogus)